O
Ook
I have been told that the only difference between a class and a struct is
the default interface - private for class, public for struct. My instructor
made this statement:
Actually there are only 2 differences between classes and structs:
1) The default interface for a class is private whereas it is publie for a
struct.
2) A struct supports array-type initialization syntax in addition to
constructors whereas a class requires constructors only.
And give the following code example:
// Works
class Point { int x, y; };
Point p1 = {4, 6};
// Compile error: 'p1' : non-aggregates cannot be initialized with
initializer list
struct Point { int x, y; };
Point p1 = {4, 6};
Is this correct, and these are the only 2 differences?
the default interface - private for class, public for struct. My instructor
made this statement:
Actually there are only 2 differences between classes and structs:
1) The default interface for a class is private whereas it is publie for a
struct.
2) A struct supports array-type initialization syntax in addition to
constructors whereas a class requires constructors only.
And give the following code example:
// Works
class Point { int x, y; };
Point p1 = {4, 6};
// Compile error: 'p1' : non-aggregates cannot be initialized with
initializer list
struct Point { int x, y; };
Point p1 = {4, 6};
Is this correct, and these are the only 2 differences?