Bonjour,
J'ai un programme qui fonctionnait bien jusqu'a ce je fasse une separation de la definition et declaration des classes dans des fichiers respectifs .cpp et .h.
Cependant, maintenant j'obtiens le bug le message d'erreur ci-dessous.
Les fichiers en question sont ci-dessous:
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 1>------ Build started: Project: TraceFlowManager2, Configuration: Debug Win32 ------ 1>Compiling... 1>FlowTracerMain.cpp 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(518) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1> c:\program files\microsoft visual studio 9.0\vc\include\stack(21) : see reference to class template instantiation 'std::deque<_Ty>' being compiled 1> with 1> [ 1> _Ty=debugFlowTracer 1> ] 1> c:\designcpp\include\flowtracermanager.h(9) : see reference to class template instantiation 'std::stack<_Ty>' being compiled 1> with 1> [ 1> _Ty=debugFlowTracer 1> ] 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(518) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(518) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(518) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(519) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(519) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(519) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(519) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\moondragon\distancelearning\cpp\code\traceflowmanager2\flowtracermain.cpp(4) : error C2059: syntax error : 'namespace' 1>c:\moondragon\distancelearning\cpp\code\traceflowmanager2\flowtracermain.cpp(4) : error C2238: unexpected token(s) preceding ';' 1>c:\moondragon\distancelearning\cpp\code\traceflowmanager2\flowtracermain.cpp(39) : fatal error C1075: end of file found before the left brace '{' at 'c:\designcpp\include\flowtracer.h(12)' was matched 1>FlowTracerManager.cpp 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(518) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1> c:\program files\microsoft visual studio 9.0\vc\include\stack(21) : see reference to class template instantiation 'std::deque<_Ty>' being compiled 1> with 1> [ 1> _Ty=debugFlowTracer 1> ] 1> c:\designcpp\include\flowtracermanager.h(9) : see reference to class template instantiation 'std::stack<_Ty>' being compiled 1> with 1> [ 1> _Ty=debugFlowTracer 1> ] 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(518) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(518) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(518) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(519) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(519) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(519) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\program files\microsoft visual studio 9.0\vc\include\deque(519) : error C2027: use of undefined type 'debugFlowTracer' 1> c:\designcpp\include\flowtracer.h(12) : see declaration of 'debugFlowTracer' 1>c:\designcpp\source\flowtracermanager.cpp(6) : error C2838: 'm_Instance' : illegal qualified name in member declaration 1>c:\designcpp\source\flowtracermanager.cpp(9) : error C2535: 'void debugFlowTracer::AddFlow(void)' : member function already defined or declared 1> c:\designcpp\include\flowtracer.h(18) : see declaration of 'debugFlowTracer::AddFlow' 1>c:\designcpp\source\flowtracermanager.cpp(14) : error C2535: 'void debugFlowTracer::RemoveFlow(void)' : member function already defined or declared 1> c:\designcpp\include\flowtracer.h(19) : see declaration of 'debugFlowTracer::RemoveFlow' 1>c:\designcpp\source\flowtracermanager.cpp(17) : fatal error C1075: end of file found before the left brace '{' at 'c:\designcpp\include\flowtracer.h(12)' was matched 1>Generating Code... 1>Build log was saved at "file://c:\MoonDragon\DistanceLearning\cpp\code\TraceFlowManager2\Debug\BuildLog.htm" 1>TraceFlowManager2 - 23 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
=====================
Flowtracer.h
=====================
==============================
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 #ifndef _FLOWTRACER_H_ #define _FLOWTRACER_H_ #include <string> #include <stack> #include <vector> #include <stdio.h> FILE * pFile; class debugFlowTracer { private: std::string m_sFlowName; std::vector< debugFlowTracer > m_activefunctionStack; bool m_bRemoved; protected: virtual void AddFlow(); virtual void RemoveFlow(); public: debugFlowTracer(void) { m_sFlowName = "Unknown"; m_bRemoved = false; AddFlow(); } debugFlowTracer(const char *strFlow) { m_sFlowName = strFlow; m_bRemoved = false; AddFlow(); } debugFlowTracer( const debugFlowTracer& aCopy ) { m_sFlowName = aCopy.m_sFlowName; std::vector< debugFlowTracer >::const_iterator iter; for ( iter = aCopy.m_activefunctionStack.begin(); iter != aCopy.m_activefunctionStack.end(); ++iter ) m_activefunctionStack.insert( m_activefunctionStack.end(), (*iter) ); } ~debugFlowTracer(void) { if ( !m_bRemoved ) RemoveFlow(); m_bRemoved = true; } std::string Name() { return m_sFlowName; } void AddSubFlow( debugFlowTracer& cSubFlow ) { // Just push it on top of the active function stack m_activefunctionStack.insert( m_activefunctionStack.end(), cSubFlow ); } void PrintStack(int iLevel) { pFile = fopen ("myfile.txt","a");//PSA std::vector< debugFlowTracer >::iterator iter; for ( iter = m_activefunctionStack.begin(); iter != m_activefunctionStack.end(); ++iter ) { for ( int i=0; i<iLevel; ++i ) {putchar ('\t'); //putchar writes character to the current position in the standard output (stdout) and advances the internal file position indicator to the next position. fputc ( ('\t'), pFile ); } printf("Level:%d %s\n", iLevel,(*iter).Name().c_str()); fprintf (pFile, "Level: %d %s\n",iLevel,(*iter).Name().c_str()); (*iter).PrintStack(iLevel+1); } //fclose (pFile); }; #endif
FlowTracerManager.h
==============================
=============================
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 #ifndef FLOWTRACERMANAGER_H #define FLOWTRACERMANAGER_H #include "FlowTracer.h" class debugFlowTracerManager { private: std::stack< debugFlowTracer> m_functionStack; static debugFlowTracerManager *m_Instance; public: static debugFlowTracerManager *Instance() { if ( m_Instance == NULL ) m_Instance = new debugFlowTracerManager(); return m_Instance; } void addFlow( debugFlowTracer& cFlow ) { m_functionStack.push( cFlow ); } void removeFlow(debugFlowTracer& cFlow) { if ( m_functionStack.empty() ) return; // Get the top element debugFlowTracer t = m_functionStack.top(); // Remove it. m_functionStack.pop(); // If there is anything left, add it if ( m_functionStack.empty() ) { pFile = fopen ("myfile.txt","a");//PSA printf("Flot [%s]:\n", t.Name().c_str() ); fprintf (pFile,"Flot [%s]:\n", t.Name().c_str() ); //fclose (pFile); t.PrintStack(0); } else m_functionStack.top().AddSubFlow( t ); } private: debugFlowTracerManager() { } debugFlowTracerManager(const debugFlowTracerManager& aCopy ) { } virtual ~debugFlowTracerManager(void) { } }; #endif
FlowTracerManager.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 #include "FlowTracer.h" #include "FlowTracerManager.h" debugFlowTracerManager *debugFlowTracerManager::m_Instance = NULL; void debugFlowTracer::AddFlow() { debugFlowTracerManager::Instance()->addFlow( *this ); } void debugFlowTracer::RemoveFlow() { debugFlowTracerManager::Instance()->removeFlow( *this ); }
FlowTracerMain.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
36
37
38 #include <iostream> #include "FlowTracerManager.h" using namespace std; void func_3() { debugFlowTracer flow("func_3"); } void func_2() { debugFlowTracer flow("func_2"); func_3(); } void func_1() { debugFlowTracer flow("func_1"); func_2(); } int main(int argc, char* argv[]) { debugFlowTracer mainFlow("main"); func_1(); func_2(); func_3(); //cout << "Ok!" << endl; return 0; //system ("BREAK"); //return EXIT_SUCCESS; }
Partager