OOP question

I was wondering what is the main differences between a struct and a class?

popa
Last edited on
struct defaults to public inheritance and public members.
class defaukts to private inheritance and private members.
Other than that there is no difference.
1
2
3
4
5
6
7
8
9
10
struct foo: bar
{
    int baz;
}
//equivalent to
struct foo: public bar
{
public:
    int baz;
}
class foo: bar
{
    int baz;
}
//equivalent to
class foo: private bar
{
private:
    int baz;
}
Hellouu

As much as I know,
in C++, the only difference between a struct and a class is that struct members are public by default, and class members are private by default
which doesnt mean, you should rely on those Defaults and dont use the keywords ;)

There were quite a lot of questions like These before... Just search in Google for "c++ difference struct and class" and you'll find some more detailed Information. :)
Last edited on
Topic archived. No new replies allowed.