salut à tous
je viens de passer sur Visual studio 2003 et le code suivant en C++ ne compile pas. je voulais me faire la main sur les threads en repartant d'un exemple tout fait tiré de msdn.
je pense qu'il s'agit d'un probleme de lien vers les bibliotheques ou qqch comme ca mais je suis totalement debutant sur visual.
thread.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #include "stdafx.h" # include "thread.h" #using <mscorlib.dll> using namespace System; int _tmain(){ Console::WriteLine( "Main thread: Start a second thread." ); // Create the thread, passing a ThreadStart delegate that // represents the ThreadExample::ThreadProc method. For a // delegate representing a static method, no object is // required. Thread^ oThread = gcnew Thread( gcnew ThreadStart( &ThreadExample::ThreadProc ) ); // Start the thread. On a uniprocessor, the thread does not get // any processor time until the main thread yields. Uncomment // the Thread.Sleep that follows t.Start() to see the difference. oThread->Start(); //Thread::Sleep(0); for ( int i = 0; i < 4; i++ ) { Console::WriteLine( "Main thread: Do some work." ); Thread::Sleep( 0 ); } Console::WriteLine( "Main thread: Call Join(), to wait until ThreadProc ends." ); oThread->Join(); Console::WriteLine( "Main thread: ThreadProc.Join has returned. Press Enter to end program." ); Console::ReadLine(); return 0; }
thread.h
voici le rapport d'erreur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 using namespace System; using namespace System::Threading; // Simple threading scenario: Start a Shared method running // on a second thread. public ref class ThreadExample { public: // The ThreadProc method is called when the thread starts. // It loops ten times, writing to the console and yielding // the rest of its time slice each time, and then ends. static void ThreadProc() { for ( int i = 0; i < 10; i++ ) { Console::Write( "ThreadProc: " ); Console::WriteLine( i ); // Yield the rest of the time slice. Thread::Sleep( 0 ); } } };
c:\Documents and Settings\o.arnaud\Mes documents\Visual Studio Projects\thread\thread\thread.h(8) : error C2059: erreur de syntaxe : 'public'
c:\Documents and Settings\o.arnaud\Mes documents\Visual Studio Projects\thread\thread\thread.h(9) : error C2143: erreur de syntaxe : absence de ';' avant '{'
c:\Documents and Settings\o.arnaud\Mes documents\Visual Studio Projects\thread\thread\thread.h(9) : error C2447: '{' : en-tête de fonction manquant (liste formelle à l'ancien format ?)
thread.cpp(18) : error C2143: erreur de syntaxe : absence de ';' avant '^'
thread.cpp(18) : error C2143: erreur de syntaxe : absence de ';' avant '^'
thread.cpp(18) : error C2653: 'ThreadExample' : n'est pas un nom de classe ni d'espace de noms
thread.cpp(23) : error C2065: 'oThread' : identificateur non déclaré
thread.cpp(23) : error C2227: la partie gauche de '->Start' doit pointer vers un class/struct/union
le type est ''unknown-type''
thread.cpp(33) : error C2227: la partie gauche de '->Join' doit pointer vers un class/struct/union
le type est ''unknown-type''
thread.cpp(33) : error C3861: 'oThread': identificateur introuvable, même avec une recherche qui dépend de l'argument
Partager