Structs in Classes

Is it possible to create structs in classes, and then inherit from
another class.
I mean the class, to inherit from another class with the struct still intact

Thanks
closed account (o3hC5Di1)
Hi there,

I believe this is what you intend:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

class foo
{
    public:
        struct foofoo {
            int number;
        };
};

class bar : public foo
{
    public:
        foo::foofoo foobar;
};
int main()
{
    bar b;
    b.foobar.number = 10;
    
    std::cout << b.foobar.number;
}


Running example: http://coliru.stacked-crooked.com/a/b2f85b2cdd9332ab
Please let us know if you require any further questions.

All the best,
NwN
THANK YOU VERY MUCH
Topic archived. No new replies allowed.