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
  • 4,098
  • 12
  • 47
  • 79

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,882
  • 9
  • 57
  • 104