I am new to C++, I need to use class object' member function as a thread function, and the object is used in application class and object cannot be shared so it is a unique pointer. When I am trying to create the thread, I am getting the compilation error.
I cannot copy the code as is so just created a sample code snippet.
DerivedType
<-Base3Type
<-Base2Type
<-Base1Type
- DerivedType
is declared as private in application class
class AppClass
{
private:
std::unique_ptr<DerivedType> transport;
public:
}
AppClass::Open()
{
transport= std::make_unique<DerivedType>(client, logger);
std::thread receive(&DerivedType::receive, &transport, flag, 1000);//flag and 100 are arguments to DerivedType::receive function.
}
I am getting the following compilation error
/usr/include/c++/5.2.1/functional:634:20: **error: pointer to member type ‘void (Base1Type::Base2Type::Base3Type::DerivedType::)(std::shared_ptr<bool>, const short unsigned int&)’ incompatible with object type ‘std::unique_ptr<Base1Type::Base2Type::Base3Type::DerivedType>’**
{ return ((*__ptr).*_M_pmf)(std::forward<_Args>(__args)...); }
^
/usr/include/c++/5.2.1/functional:634:60: **error: return-statement with a value, in function returning 'void' [-fpermissive]**
{ return ((*__ptr).*_M_pmf)(std::forward<_Args>(__args)...); }
Please let me know how to get it compiled and execute without crash. Thank you.