A Class declaration question

I'm looking at a class that is declared like the example below, can someone explain this declaration? Is this 2 classes foo and boo or is this boo of type foo and foo is the base class. Any help would be appreciated.
class foo boo
{

public:



} ;
If you were to write this with a colon ( : ) before the "boo" then the class foo would derive from boo.

e.g.
1
2
3
4
5
6
7
class boo{
    int a;
};
class foo: boo{
    int b;
    //int a is also present as it is inherited from boo
};


If you were to write this but moving the "boo" to just after the closing curly brace then this would be declaring a variable boo of type foo.
e.g.
1
2
3
4
5
6
7
8
class foo{
}boo;

//is the same as this

class foo{
};
foo boo;


P.S... Maybe this should go in under the beginner forums?
Last edited on
Thanks
Last edited on
Note that by default anything declared for a class is private data, including inherited classes.

1
2
3
4
5
6
7
8
9
class boo{
public:
    int a;
private:
    int b;
};
class foo: boo{
    int c;
};


PUBLIC: boo.a
PRIVATE: foo.a, foo.b, foo.c

1
2
3
4
5
6
7
8
9
class boo{
public:
    int a;
private:
    int b;
};
class foo: public boo{
    int c;
};

PUBLIC: boo.a, foo.a (now that the contents of boo are lowest privacy public)
PRIVATE: boo.b, foo.b, foo.c
Topic archived. No new replies allowed.