I am trying to create a class Parallel
which is a subclass of std::thread
,therefore my class is defined in Parallel.h
,but the main method defined in separate file main.cpp
in same project(in visual studio).When I create an instance of Parallel
and execute join()
function in main()
method as below code segment:
I am new to C++, here is the "Parallel.h"-
#include<thread>
using namespace std;
namespace Para{
class Parallel:thread
{
public:
static void run(){
}
Parallel(void)
{
}
virtual ~Parallel(void)
{
}
inline static void start(Parallel* p){
// (*p).join();
}
virtual void Parallel::start(thread& t){
}
static void parallelize(Parallel& p1,Parallel& p2){
}
inline virtual Parallel* operator=(thread* t){
return static_cast<Parallel*>(t);
}
}
//in main.cpp
void main(){
Parallel p;
p.join();
thread t(print);
t.join();
system("Pause");
}
Problem is how to define a proper subclass of a thread class having a overloaded constructor taking function name as a parameter,also
when defined p.join()
compiler given following errors in VS2012:
Error 2 error C2247: 'std::thread::join' not accessible because 'Para::Parallel' uses 'private' to inherit from 'std::thread' C:\Users\Gamer\Desktop\PROJECQ\VC++@OMAQ\CQ47\CQ47\main.cpp 11
3 IntelliSense: function "std::thread::join" (declared at line 209 of "H:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\thread") is inaccessible c:\Users\Gamer\Desktop\PROJECQ\VC++@OMAQ\CQ47\CQ47\main.cpp 11
Parallel
class declaration.std::thread
, but simply to pass a function or function object of your choosing tostd::thread
's constructor.std::thread
as a member variable of your class?