Re: "[Classname] was not declared in this scope"

  • Follow


William wrote:
>> In Peer.h, I have:
>>
>> class Peer {
>>        // ...
>>
>> };

I think that you probably left something important out out in what you
have shown us here but this can still be solved.  The include stack
gives us a hint:

>>  In file included from Communications.h:19,
>>                  from Peer.h:4,
>>                  from Peer.cc:1:
>> Overseer.h:11: error: `Peer' was not declared in this scope

Peer.h actually includes Overseer.h indirectly.  Let's think about what
the preprocessor does in Peer.cc:

#include "Peer.h"  --> go through the include gaurd  (#ifndef PEER_H)
but not as far as Peer's class defintion.
--> #include "Communications.h"
--> #include "Overseer.h"
--> #include "Peer.h" --> but can't make it though the include gaurd so
Peer class still not defined.  Now we continue to try to use Peer in
Overseer and your compiler complains because it's not defined yet.

Basically, you have a cycle in your headers.  You can probably just
forward declare Overseer in Communications.h or just forward declare
Communications (or whatever) in Peer.h.  If you don't feel that you can
break this cycle you should probably reconsider your design.  These
cycles generally indicate that there are too many dependencies in the
design.  Cheers,

-Ryan

PS -- Michael is right, you should try to get out of the habit of
"using namespace std;" in headers (and shun those who do! j/k.  ;-)


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply ryan.gallagher (2) 3/22/2005 10:41:08 PM


0 Replies
220 Views

(page loaded in 0.095 seconds)

Similiar Articles:













7/30/2012 12:33:00 PM


Reply: