is there a way, to access a class member variable from within a struct member function defined within this class?
Atm, the only solution that comes to my mind would be to add fProperty to struct S as well and initialize S.fProperty
with A.fProperty
(or add a reference to the parenting class) when creating an instance of S but that does not seem to ideal to me.
Thanks a lot already for your help and let me know if I can make this post more clear (first post here).
class A {
struct S {
void funcS(float theNumber) {if (theNumber > XXXfProperty) {// do sth}}
};
A(float theProperty):(fProperty(theProperty)){}
void funcA(){
S s;
s.funcS(complicatedFunction());
}
float fProperty; // want to access this number from all instances of S I create somewhere within class A implementation.
};
int main(){
A a1(1.);
A a2(10.);
}
Source: Windows Questions C++