【发布时间】:2014-06-09 17:15:47
【问题描述】:
编辑:正确的标题应该是“在基类中调用重载的真实虚函数”,因为这是问题的很大一部分。
我有一个带有真正虚函数的基类和其他几个普通的。其中一个正常调用线程中的虚函数,我在该行中收到错误,我不明白。我猜这和线程有关,但是由于基类是抽象的,每个派生类都必须实际实现虚函数,应该没有问题。也许这是完全不同的东西。这或多或少是这样的:
class Base {
virtual int getInfo(int a) = 0; // the culprit?
void getInfo(); // is implemented, calls getInfo(int); Does
// actually have the same name. Works perfectly fine.
void getThreadedInfo(); // for details, see below
}
// ..later..
Base::getThreadedInfo() {
...
for(int i=0; i<maxThreads; i++) {
threads.push_back(thread(getInfo, i)); // this is line 85
}
...
}
完整的错误信息是:
Error 1 error C3867: 'Base::getInfo': function call missing argument list; use '&Base::getInfo' to create a pointer to member
c:\path\to\base.cpp 85 1 Project
Error 2 error C2661: 'std::thread::thread' : no overloaded function takes 2 arguments
c:\path\to\base.cpp 85 1 Project
【问题讨论】:
标签: c++ multithreading visual-studio-2010 virtual