【发布时间】:2015-12-19 05:42:58
【问题描述】:
我有一些类似的东西:
class Parent
{
private:
std::thread t1;
protected:
void ThreadFunction()
{
while(true)
{
SpecializedFunction();
}
}
void CreateThread()
{
t1 = std::thread(&Parent::ThreadFunction, *this);
}
virtual void SpecializedFunction() = 0;
public:
void Run()
{
CreateThread();
}
}
class Child1 : public Parent
{
protected:
void SpecializedFunction()
{
//code
}
}
class Child2 : public Parent
{
protected:
void SpecializedFunction()
{
//code
}
}
但我有编译错误(如果我注释线程创建行,它会编译)。它说它不能专门化衰变方法。我认为问题要么是 Parent 是抽象的,要么是线程函数受到保护,但我不确定。您能否提出解决方法/解决方案?
谢谢!
【问题讨论】:
-
删除
*,但要注意生命周期问题。
标签: multithreading templates c++11 polymorphism virtual