내가 가진 가정 내 테스트에서기본 클래스에 대한 참조를 boost :: thread에 전달하고 파생 클래스에서 가상 함수를 호출 할 수 있습니까?
class Base
{
public:
void operator()()
{
this->run();
}
virtual void run() {}
}
class Derived : public Base
{
public:
virtual void run()
{
// Will this be called when the boost::thread runs?
}
}
int main()
{
Base * b = new Derived();
boost::thread t(*b); // <-- which "run()" function will be called - Base or Derived?
t.join();
delete b;
}
, 나는 Derived::run()
호출 할 수 없습니다. 나는 잘못된 것을하고 있습니까, 아니면 불가능합니까?
또는'boost :: ref (* b)'를 전달하십시오. – GManNickG