質問

I have a base class and the derived class. I need to access the protected member of the base class in the derived class. However, Eclipse does not allow me to access the data member as if it were a member of a derived class without caring that it was inherited. How do I do that?

class BaseClass {
protected:
static int a;
int b;
}


class DerivedClass: public BaseClass {    
void SomeMethod {    
a=10; // cannot resolve symbol
b=10; // cannot resolve symbol
BaseClass::a=10; //does not complain
BaseClass::b=10; //does not complain    
}
}
役に立ちましたか?

解決

I couldn't completely understand your question, but fixing the syntax errors, the following should work:

class BaseClass {
protected:
static int a;
int b;
}; // <-- Missing semicolon

int BaseClass::a = 0; // Define static member

class DerivedClass: public BaseClass {    
void SomeMethod() { // <-- Missing ()
a=10;
b=10; 
}
};// <-- Missing semicolon
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top