C++ Compilation Error
Hi,
I have a class BaseClass, and another one called DerivedClass. The problem is, I'm getting the following error while compiling: Code:
error: expected class-name before ‘{’ token Code:
error: forward declaration of ‘struct BaseClass’ Code:
class DerivedClass : public BaseClass |
Can you please post a complete, tiny program which illustrates the problem?
By "complete", I mean something that can be compiled exactly as you post it, without modifications. By "tiny", I mean as small as possible and still be "complete" and still illustrate this problem, and only this one problem. Please put the program in CODE markers:
|
Yes, do post examples.
Off the top of my head, though, I'd say you're missing a semi-colon after the closing brace of your base class declaration. |
Well, the problem is, I have no idea what's causing this problem, so I have no idea how to reproduce it :( Any suggestions on that?
|
why don't you post it all then?
paul |
Posting it all is certainly one way forward.
A better way is to make a working temporary copy of the program, and strip as much out of that program as you can and still make the error occur. You might find out at that point just what the error is without consulting us further. That would be cool. If that doesn't happen, just post that small program (but complete, so we can compile it and play with it). |
The problem is that BaseClass is only a forward declaration. Base classes must be completely declared types (or otherwise the calculations to figure out the size of the derived type wouldn't work, among other things).
|
i still can't figure out compile errors without some code:Pengy: or more code at least
paul |
Very well then. Let me experiment how much of the code I can strip and still reproduce the error.
@tuxdev: I find your reasoning logical. However, I still do not understand how I can go about fixing this problem. Any suggestions? |
Just so you know, BaseClass is an abstract class. I hope that doesn't make any difference?
|
The following simplified program works:
main.cpp Code:
#include <iostream> Code:
#include <iostream> Code:
using namespace std; Code:
using namespace std; Code:
2 main.cpp In file included from main.cpp |
Yup, I've confirmed, and then reconfirmed that all the header files are being included and stuff. But I still can't figure out the problem. I'll get back to you guys with some code.
|
Then maybe your configure guard is messed up? The #define it keys off of has to be unique, and sometimes one forgets to change that if you copy-and-hack from another file.
|
I'm sorry? I didn't get that. Could you please elaborate? And I've stripped the code as much as I could. How do I give it to you guys? It's still too much to post here.
|
I'm sorry? I didn't get that. Could you please elaborate? And I've stripped the code as much as I could. How do I give it to you guys? It's still too much to post here.
|
All times are GMT -5. The time now is 01:06 PM. |