C++ non-sensical errors: c2629 "Unexpected class", c2065: 'ceil' undeclared identifer [closed]
I had a program working yesterday, moved one function from one class in one file to another class/file, and all of a sudden I got a series of non-sensical errors:
- c2629: Unexpected class blahblah at the beginning of several header files
- c2065: 'ceil' undeclared identifier
- c2039: xxxx is not a member of namespace yyyy (when it most certainly is, and the file is included)
I've spent about a day now trying to figure out what's going on, and I can't figure it out. There's 50+ files so no point in posting the code, so I guess my question is, what sorts of things do you look for in order to debug errors like this?
I've checked:
- Making sure there's proper header guards in all .h files
- Making sure all classes have semicolons at the end
- Putting "using" directives only in .cpp files, or else in a namespace
- Looking for mismatched curly brackets
I'm at wits end. Sorry for the lack of code/information. Appreciate any help, thanks.
Always start with the first error and solve that first. Don't get bogged down by the loads of errors since the compiler may be lose its sense of grammar on the first nasty error (typically a missing semicolon after a struct/class).
When you copied the function definition, did you replace the class name in that function definition with the new class? ie.
void oldclass::func()
{
}
becomes:
void newclass::func()
{
}
i know it sounds trivial... but you did ask for suggestions :D
Check that you haven't inserted some character at the start of one of your source files by mistake. This has happened to me a few times, and can give strange errors in the included header files.
精彩评论