I am unsure about the order of declaration in my class. My compiler says error: "Foo" was not declared in this scope
. If I change the order of public
and private
parts of the class, I end up with the same error. Also, if I want to use the getFoo()
, and I am including my header file, the struct Foo type is not visible because it's private. But if I put it in public scope again, then public would have to come before private because otherwise the declaration of myFoo
of type Foo
can't happen since Foo
was not decalred yet.
I am confused here... thanks for your help!
/*MyClass.h*/
class MyClass
{
private:
struct Foo{
int bar;
};
Foo myFoo;
public:
Foo getFoo(){ return myFoo;}
};