i trying follow tutorial @ http://www.drdobbs.com/cpp/ccli-threading-part-i/184402018 thread programming in winform in visual c++. opened win32 console project , added empty cpp file inside placed code follows:
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->name; (int = loopstart; <= loopend; ++i) { if ( % dispfrequency == 0) { console::writeline("{0} : = {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, &threadx::threadentrypoint)); t1->name = "t1"; threadx o2 = gcnew threadx(-1000000, 0, 200000); thread^ t2 = gcnew thread(gcnew threadstart(o2, &threadx::threadentrypoint)); t1->name = "t2"; t1->start(); t2->start(); console::writeline("primary thread terminating"); }
however gives me errors such :
- error c2726: 'gcnew' may used create object managed type
- error c2440: 'initializing' : cannot convert 'threadx *' 'threadx' no constructor take source type, or constructor overload resolution ambiguous
- error c3364: 'system::threading::threadstart' : invalid argument delegate constructor; delegate target needs pointer member function
you mixing c++ , c++/cli different thing. replace
public class threadx
with
public ref class threadx
Comments
Post a Comment