0

Do C++ struct also call constructors (default, copy constructors) and destructors just like classes or they follow the C language guidelines for struct? So in the example below, is a default constructor called?

Foo structObject; \\Foo is a struct
vkaul11
  • 3,712
  • 8
  • 42
  • 67

1 Answers1

5

Yes, they do. The only difference between struct and class in C++ is in visibility of it's members. Struct has by-default members public, class private.

Effectively, writing

class A {
public:
//// ...
}

is the same as writing

struct A {
//// ...
}
nothrow
  • 15,384
  • 7
  • 54
  • 101