# Another "odd" error.

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm having this compliling error error C2146: syntax error : missing ';' before identifier 'm_TabCtrl' error C2501: 'CCharts::MyTabCtrl' : missing storage-class or type specifiers error C2501: 'CCharts::m_TabCtrl' : missing storage-class or type specifiers for this code ... #pragma once #include "MyTabCtrl.h" ... // Dialog Data enum { IDD = IDD_CHARTS }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support DECLARE_MESSAGE_MAP() public: MyTabCtrl m_TabCtrl; afx_msg void OnPaint(); afx_msg void OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult); }; ... The error is at the MyTabCtrl line. I cannot figure out what is wrong with how I've declared it. I think it must be a header problem. The thing that is so odd is that I'm getting several forms of this same error. I had tried earlier to include a different file "mytype.h" and declared "mytype MyType;" in the header file. This gave me the exact same error. When I moved the declaration to the .cpp file, however, no error. Furthermore, I've included "mytype.h" in several other files and it has worked fine. Any ideas? I've looked through several forums. This seems to be a common problem but I couldn't find any suitable solutions.

##### Share on other sites
DECLARE_MESSAGE_MAP();

##### Share on other sites
It sounds like it can't find your class declaration. I have this problem sometimes when you have lots of things #including each other and they are compiled in a bad order. For example, suppose class A needs class B, and class B needs classes A and C. If A is included first, it goes to include B, which then includes A and C, but it finds the "pragma once" and ignores A.h thinking class A has already been declared when it actually has not, so you get an error because it doesn't recognize class A. Your case may be much more complicated (like A needs B needs C needs D needs E needs A), but when this problem has arisen for me I've had very similar errors. I can generally fix this by not having any unnecessary #includes in header files (it's okay in cpps), and this means not #including A.h inside B.h when you only have a pointer to an A object in class B, just add "class A;" before the declaration.

Hope this helps.

##### Share on other sites
Quote:
 Original post by xorDECLARE_MESSAGE_MAP();

I haven't used MFC for quite a while, but if I remember correctly the DECLARE_MESSAGE_MAP() macro isn't supposed to have a semicolon after it. I could be wrong though, and I don't have access to a compiler at the moment.

##### Share on other sites
yeah, you are right. DECLARE_MESSAGE_MAP() isn't supposed to have a ';' after it. However, I tried it with a ';' after it and it didn't make any difference. Maybe it doesn't matter whether or not it has a ';' after it.

Anyway, I think you were on the right track with the whole .h thing. I have files included all over the place. For some reason, I thought I could do this but it seems like maybe it is a bad thing.

I'm not sure exactly what you mean by include class A; before it. I removed #include A.h from B.h and I tried inserting 'class A;' right above my class B declaration in B.h but it didn't do anything.

I also tried A::A *ptrA; in the class B declaration but that also failed saying A is not a class (although it is).

##### Share on other sites
is "MyTabCtrl.h" including the file you posted? If so, MyTabCtrl hasn't been defined, yet.

Put this at the end of "MyTabCtrl.h", right before #endif:

#pragma message("Hello from " __FILE__ " : " __LINE__)

And put the same message at the end of the .h file you posted. See which line is output first, when compiling. That should tell you if MyTabCtrl class is getting defined before the other file is processed.

##### Share on other sites
Ok, you guys were a big help. I really appreciate it. The #pragma message thing is a good little debugging tip.

The problem was I had some weird series of includes. I had something like A.h including B.h and B.h including A.h only with more levels and a bit more complicated.

##### Share on other sites
Quote:
 The problem was I had some weird series of includes. I had something like A.h including B.h and B.h including A.h only with more levels and a bit more complicated.

in my projects i found an easy way to avoid this. i have a header called std.h (std=standard) this looks something like this:

#pragma once#include <windows.h>...class CMyFirstClass;class CMySecondClass;...#include "MyFirstClass.h"#include "MySecondClass.h"...#endif

and all other headers and sources just have to #include "std.h" and nothing else. I hope this helps.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633319
• Total Posts
3011342
• ### Who's Online (See full list)

There are no registered users currently online

×