TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: Neil Heller
from: Darin McBride
date: 2003-01-09 10:34:36
subject: Declaring a pointer to a

Hello Neil!

Replying to a message of Neil Heller to All:

 NH> I've found a programmatic solution that I think should heal the lame
 NH> and  let the blind see.  Unfortunately, my compiler doesn't share the
 NH> same  opinion.  The situation is like this:

 NH> file:  a.h

 NH>      class a_class
 NH>      {
 NH>           // some stuff
 NH>      };


 NH> file:  b.h

 NH>      #include "a.h"

 NH>      class b_class
 NH>      {
 NH>           a_class * pa_class;     // the first error... why ?
 NH>           // some other stuff
 NH>           public:  b_class(int, a_class *);
 NH>      }

This should all work fine.  I would add to the top of a.h:

#ifndef __cplusplus
# error not in C++ mode!
#endif

Just to make sure we're compiling in C++ mode rather than C mode.

Further, in b.h, you don't really need to include a.h (at least not from
what you have above).  Replace:

#include "a.h"

with:

class a_class;

And everything should work as before.  You only need a.h if you need to
call any of a_class's functions, create a new a_class object (either on the
stack or the heap), etc.  If all you have is a pointer, then you don't need
the overhead of the header file.  You'll need to include a.h in b.cpp,
though.

 NH> What I want to do is have a pointer to a_class inside b_class.  
 NH> Theoretically the way I would give it a value would be like this:

 NH> file:  a.cpp

b.cpp?  ;-)

 NH>      #include "b.h"

 NH>      b_class = new b_class(1, this);

 NH> The problem I'm having is that my compiler gives the first error as:
 NH> 'a_class':  missing decl-specifiers.

 NH> My questions are:  "What are decl-specifiers?".
 NH>                    "What did I do wrong here?".

How are you testing this?  Compiling the header file, or through your
theoretical cpp file?

Darin
C_PLUSPLUS moderator
dmcbride{at}tower.to.org

---
* Origin: Tanktalus' Tower BBS (1:250/102)
SEEN-BY: 633/267 270
@PATH: 250/102 99 10/345 379/1 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.