C++ Classes: Which are the differences between 'struct' and 'class'?
Q: Which are the differences between struct and class?
A: In C++ programming language, there is no difference between classes defined by using struct or class keywords, except the default access to members and base classes.
for struct the default access is public;
for class the default access is private.
Examples
Code:
struct SFoo : Base
{
int m_foo;
void Foo();
};
is equivalent to
Code:
struct SFoo : public Base
{
public:
int m_foo;
void Foo();
};
Code:
class CFoo : Base
{
int m_foo;
void Foo();
};
is equivalent to
Code:
class CFoo : private Base
{
private:
int m_foo;
void Foo();
};
Bookmarks