我对C++很陌生,但我想我明白发生了什么。父类正试图在父类中调用纯虚拟成员函数。我认为通过覆盖子类中的虚函数,它会被调用。从父类调用纯虚函数
我在做什么错?
在parent.h
class Parent
{
public:
virtual void run() = 0;
protected:
/** The function to starter routine and it will call run() defined by the
* appropriate child class.
* @param arg Arguments for the starter function
*/
static void * init (void * arg);
};
我试图做到这一点在parent.cpp
void * Parent::init(void * arg)
{
run();
}
在我child.h提供给我,我有这样的:
class Child : public Parent
{public:
//...
virtual void run();
//...
};
而在child.cpp我有:
void Child::run()
{
sleep(10);
}
parent.cpp中的函数init是无法编译的地方。我如何从父类调用派生函数?我所有的googleing都只提出了有关在子构造函数中不调用虚函数的注释。
任何帮助都将不胜感激。
看看您的问题在这里得到解答:http://www.parashift.com/c++- faq-lite/virtual-functions.html – Artelius 2009-10-16 22:49:32