multithreading - How to create a subclass of thread Class properly in C++(subclass of std::thread) -
i trying create class parallel
subclass of std::thread
,therefore class defined in parallel.h
,but main method defined in separate file main.cpp
in same project(in visual studio).when create instance of parallel
, execute join()
function in main()
method below code segment: new c++, here "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 how define proper subclass of thread class having overloaded constructor taking function name 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' inherit 'std::thread' c:\users\gamer\desktop\projecq\vc++@omaq\cq47\cq47\main.cpp 11
3 intellisense: function "std::thread::join" (declared @ line 209 of "h:\program files (x86)\microsoft visual studio 11.0\vc\include\thread") inaccessible c:\users\gamer\desktop\projecq\vc++@omaq\cq47\cq47\main.cpp 11
the error "uses 'private' inherit" when try call 'p.join()' because have written:
class parallel:thread
when should have written:
class parallel : public thread
the default private inheritance, means methods of base class become private on inheriting class. have specify inheritance should public if want them accessible.
Comments
Post a Comment