As I pointed out in my comment to
AwildaHarrison's answer, the ONLY difference between
struct
s and
class
es, in
C++
programming language, is their
default access specifiers:
struct
default access is
public
, while
class
one is
private
. That means you might write a class and a struct with identical properties, try, for instance:
(basically, as Pete already noted,
struct
s are redundant in
C++
)
#include <iostream>
using namespace std;
struct A
{
A(){cout << "A()" << endl; }
~A(){cout << "~A()" << endl;}
};
class B
{
public:
B(){cout << "B()" << endl; }
~B(){cout << "~B()" << endl;}
};
int main()
{
A a;
B b;
cout << "sizeof(A) " << sizeof(A) << endl;
cout << "sizeof(B) " << sizeof(B) << endl;
}