Note that there are some explanatory texts on larger screens.

plurals
  1. POThread Program in visual C++/CLI giving errors
    primarykey
    data
    text
    <p>I am trying to follow the tutorial at <a href="http://www.drdobbs.com/cpp/ccli-threading-part-i/184402018" rel="nofollow">http://www.drdobbs.com/cpp/ccli-threading-part-i/184402018</a> to do thread programming in winform in visual c++. I opened a win32 console project and added an empty cpp file to it inside which i placed the code as follows:</p> <pre><code> using namespace System; using namespace System::Threading; public class ThreadX{ int loopStart; int loopEnd; int dispFrequency; public: ThreadX(int startValue, int endValue, int frequency) { loopStart = startValue; loopEnd = endValue; dispFrequency = frequency; } void ThreadEntryPoint() { String^ threadName = Thread::CurrentThread-&gt;Name; for (int i = loopStart; i &lt;= loopEnd; ++i) { if ( i % dispFrequency == 0) { Console::WriteLine("{0} : i = {1,10}", threadName, i); } } Console::WriteLine("{0} thread terminating", threadName); } }; int main() { ThreadX o1 = gcnew ThreadX(0, 1000000,200000); Thread^ t1 = gcnew Thread(gcnew ThreadStart(o1, &amp;ThreadX::ThreadEntryPoint)); t1-&gt;Name = "t1"; ThreadX o2 = gcnew ThreadX(-1000000, 0, 200000); Thread^ t2 = gcnew Thread(gcnew ThreadStart(o2, &amp;ThreadX::ThreadEntryPoint)); t1-&gt;Name = "t2"; t1-&gt;Start(); t2-&gt;Start(); Console::WriteLine("Primary Thread Terminating"); } </code></pre> <p>However this gives me errors such as :</p> <ol> <li>error C2726: 'gcnew' may only be used to create an object with managed type </li> <li>error C2440: 'initializing' : cannot convert from 'ThreadX *' to 'ThreadX' No constructor could take the source type, or constructor overload resolution was ambiguous </li> <li>error C3364: 'System::Threading::ThreadStart' : invalid argument for delegate constructor; delegate target needs to be a pointer to a member function</li> </ol>
    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