Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a subclass of thread Class properly in C++(subclass of std::thread)
    primarykey
    data
    text
    <p>I am trying to create a class <code>Parallel</code> which is a subclass of <code>std::thread</code>,therefore my class is defined in <code>Parallel.h</code>,but the main method defined in separate file <code>main.cpp</code> in same project(in visual studio).When I create an instance of <code>Parallel</code> and execute <code>join()</code> function in <code>main()</code> method as below code segment: I am new to C++, here is the "Parallel.h"-</p> <pre><code>#include&lt;thread&gt; 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&amp; t){ } static void parallelize(Parallel&amp; p1,Parallel&amp; p2){ } inline virtual Parallel* operator=(thread* t){ return static_cast&lt;Parallel*&gt;(t); } } </code></pre> <p>//in main.cpp</p> <pre><code>void main(){ Parallel p; p.join(); thread t(print); t.join(); system("Pause"); } </code></pre> <p>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 <code>p.join()</code> compiler given following errors in VS2012:</p> <blockquote> <p>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</p> <p>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</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload