考虑两个C ++类:
2018.02.26 10:25:39.226 INFO: Initializing ProtocolHandler ["http-nio-8081"]
2018.02.26 10:25:39.241 INFO: Using a shared selector for servlet write/read
2018.02.26 10:25:39.249 INFO: Starting service [Tomcat]
2018.02.26 10:25:39.250 INFO: Starting Servlet Engine: Apache Tomcat/8.5.24
2018.02.26 10:25:39.309 SEVERE: A child container failed during start
2018.02.26 10:25:39.309 SEVERE: A child container failed during start
2018.02.26 10:25:39.312 SEVERE: Failed to start component [StandardServer[-1]]
2018.02.26 10:25:43.485 INFO: Starting shutdown.
2018.02.26 10:25:43.486 INFO: Starting shutdown.
这给我一个错误C2504:' cControl':我在CPP文件中定义它时未定义基类。是否有可能无法将指针作为参数传递给虚函数?
答案 0 :(得分:0)
始终在其子类之前定义基类,因为编译器需要知道继承的基类的完整定义。因此,如果您在基类之前定义子类,C ++将抛出一个错误,指出您的基类未定义。
// base class first
class cControl{
public:
...
protected:
virtual void onUpdate(bool*) = 0;
}
// subclass second
class cTextbox : public cControl{
public:
...
protected:
void onUpdate(bool* keys);
}
值得注意的是,C ++中的构造顺序是: