I'm looking for a way to use members of a class in a struct inside that class.
See example below. The real code is more complicated but I think this illustrates my problem wel enough. I get an error saying: "IntelliSense: a nonstatic member reference must be relative to a specific object"
Please help me.
1 2 3 4 5 6 7 8 9 10 11 12
class A
{
public:
struct B
{
void Function()
{
member += 123;
}
};
int member;
};
You need an instance of the class A in order to access that variable. This is because it is possible to do something like:
1 2
typename A::B B_inst;
B_inst.Function();
Notice that in doing this, you have not instantiated the class A, so I believe that is why what you are trying to do is not compiling and you are getting the message
"a nonstatic member reference must be relative to a specific object"
But if you make the variable static, then this is possible: