I’m having an application with 2 winforms: Form1.h and TrackEdit.h. They’re both in the same namespace (“ParkCleanUp2”).
From within Form1 I call this code:
ParkCleanUp2::TrackEdit^ te;
Where it gives me these errors:
Error 24 error C2039: 'TrackEdit' : is not a member of 'ParkCleanUp2' (TrackEdit.cpp) c:\users\-joey\documents\visual studio 2010\projects\park cleanup 2\park cleanup 2\Form1.h 2332
Error 25 error C2065: 'TrackEdit' : undeclared identifier (TrackEdit.cpp) c:\users\-joey\documents\visual studio 2010\projects\park cleanup 2\park cleanup 2\Form1.h 2332
Error 26 error C2065: 'te' : undeclared identifier (TrackEdit.cpp) c:\users\-joey\documents\visual studio 2010\projects\park cleanup 2\park cleanup 2\Form1.h 2332
Though, if I go to TrackEdit.h it show me:
namespace ParkCleanUp2 {
//Some namespae includes
public ref class TrackEdit : public System::Windows::Forms::Form
So I’m wondering why it’s giving me the error “‘TrackEdit’ : is not a member of ‘ParkCleanUp2’” and why it’s looking into the TrackEdit.cpp file, while I included the .h file.
What I found to be weird, and maybe important to mention, is that when I comment the #include "Form1.h line in TrackEdit.h it just works perfect, but in TrackEdit.h I than can’t call Form1’s functions (like selected an item in a listbox) which I wanted to achieve.
It appears you have both Form1.h and TrackEdit.h each
#include-ing the other. Instead, have a forward declaration, and only include Form1.h from TrackEdit.cpp, and vise-versa.The double-include doesn’t work because you’ve got both classes referencing the other. Each class needs to know about the other in order to define itself. Since all you have is the full class definition, you’ve got a circular definition. Instead, the forward declaration provides just enough for the compiler to know “OK, there’s a class with that name, and that’s all I know about it”, and the circular dependency is resolved.
(Also: When you edited the question, you removed the most important sentence: “so basically Form1.h includes TrackEdit.h, which includes Form1.h again”. That pattern is very rarely correct. If you see yourself doing that, provide more forward declarations instead.)
Something like this:
Form1.h:
TrackEdit.h:
Form1.cpp and TrackEdit.cpp: