如何访问被覆盖的基类函数中的成员变量?
//Overridden base class function
void handleNotification(s3eKey key){
//Member variable of this class
keyPressed = true; //Compiler thinks this is undeclared.
}
编译器抱怨未声明 keyPressed。我可以弄清楚如何访问它的唯一方法是将 keyPressed 声明为公共静态变量,然后使用类似:
ThisClass::keyPressed = true;
我究竟做错了什么?
//添加的细节------------------------------ -------------
这个类.h:
include "BaseClass.h"
class ThisClass: public BaseClass {
private:
bool keyPressed;
};
ThisClass.cpp:
include "ThisClass.h"
//Overridden BaseClass function
void handleNotification(s3eKey key){
//Member variable of ThisClass
keyPressed = true; //Compiler thinks this is undeclared.
}
基类.h:
class BaseClass{
public:
virtual void handleNotification(s3eKey key);
};
基类.cpp
include 'BaseClass.h"
void BaseClass::handleNotification(s3eKey key) {
}