문제

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