Answered by:
Struct problem

Question
-
I have a problem creating a struct using VC6:
struct A { A(); ~A(); A(const A& s); // line X A& operator=(const A& s); // line Y const A& operator=(const char* str); const A& operator=(const wchar_t* str); };
First I have compiled it with no problems in a small console application.
After that, I have tried to put it together with my big MFC application and it does not compile!! The errors I get are:(X) error C2629: unexpected 'struct A (' (X) error C2238: unexpected token(s) preceding ';' (Y) error C2143: syntax error : missing ')' before 'constant' (Y) error C2143: syntax error : missing ';' before 'constant' (Y) error C2059: syntax error : 'constant' (Y) error C2059: syntax error : ')' (Y) error C2238: unexpected token(s) preceding ';'
Does anybody know what's happening?
Thanks in advance,
Wednesday, October 8, 2008 9:39 AM
Answers
-
Whne you get these compile errors, you must be compiling some implementation (.cpp file) that #include's your header containing the struct. The problem must be in something #include'd before that file.
If you doubt this, try creating a new empty .cpp file and putting just the #include's in it. Presumably, you will get the error. Try commenting out the other #include's one at a time until the problem goes away.
Basically, the technique here is to simplify the problem until the error either goes away or the cause becomes obvious.
David Wilkinson | Visual C++ MVP- Marked as answer by txandi Wednesday, October 8, 2008 3:35 PM
Wednesday, October 8, 2008 2:43 PM
All replies
-
There is nothing wrong with the struct definition you have shown.
If it compiles in a simple project but not in your MFC project the fault must lie elsewhere. Presumably this struct definition is in a header. Perhaps there is an error in another header included before it.
David Wilkinson | Visual C++ MVPWednesday, October 8, 2008 11:40 AM -
Yes, the struct definition is in a header, but I don't think there's a problem in any previous header because when I delete the line including my header, the project compiles and works fine.
More information: this struct is defined inside a namespace.Wednesday, October 8, 2008 12:03 PM -
Then maybe you need to show the entire header file. The code you have shown compiles for me.
David Wilkinson | Visual C++ MVPWednesday, October 8, 2008 12:53 PM -
I experience the problem with the header file of this project (VC6 version):
http://www.codeproject.com/KB/office/BasicExcel/BasicExcel_src.zipWednesday, October 8, 2008 1:12 PM -
Double check the headers included by this header and make sure you haven't the semicolon off of the closing brace from a class or struct definition. That's most often the cause of strange errors like these.
Wednesday, October 8, 2008 1:14 PM -
If the headers weren't ok it would have not compiled in my console project. I have not done any modification to that files.Wednesday, October 8, 2008 1:30 PM
-
Whne you get these compile errors, you must be compiling some implementation (.cpp file) that #include's your header containing the struct. The problem must be in something #include'd before that file.
If you doubt this, try creating a new empty .cpp file and putting just the #include's in it. Presumably, you will get the error. Try commenting out the other #include's one at a time until the problem goes away.
Basically, the technique here is to simplify the problem until the error either goes away or the cause becomes obvious.
David Wilkinson | Visual C++ MVP- Marked as answer by txandi Wednesday, October 8, 2008 3:35 PM
Wednesday, October 8, 2008 2:43 PM -
I have changed the order of the includes and now it works. I hope someday I could understand why.
Anyway, thanks to all.
Wednesday, October 8, 2008 3:35 PM -
txandi:
When successful compilation depends on order of #include's, it indicates that one of the headers should actually have #included the other, or possibly that one or more of your headers is missing #include guards (or #pragma once).
David Wilkinson | Visual C++ MVPWednesday, October 8, 2008 4:18 PM