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

Hello Neil!

Replying to a message of Neil Heller to Darin McBride:

 NH>>      #include "a.h"

 NH> I've kept this because I DO want to call a_class member functions.

It's only needed if you want to call them in code that's in b.h.  If all
the calls to a_class's member functions are in the .cpp file(s), then you
don't need the header here, just the forward declaration.

 NH>>      class b_class
 NH>>      {
 NH>>           a_class * pa_class;     // the first error... why ?

No idea.

 NH> It doesn't.  I get three errors (see "#1" above):

 NH> pa_class: missing decl-specifiers
 NH> syntax_error: missing ';' before identifier mpa_class
 NH> mpa_class: missing decl_specifiers


 NH> Do you think that the problem is with the compiler and not my code?  
 NH> This is something I really doubt but for the life of me I can't
 NH> figure  out what's going on here.

That's usually a safe assumption.  However, this code compiles fine here:

[0] f:\tmp\a> type *

// a.h

class a_class
{
};

// b.cpp

#include "b.h"

int main()
{
    a_class* a = new a_class;
    b_class* b = new b_class(1, a);
}
// b.h

#include "a.h"

class b_class
{
    a_class* a;
public:
    b_class(int z, a_class* a);
};

[0] f:\tmp\a>gcc -v
Using builtin specs.
gcc version 2.8.1

[0] f:\tmp\a>gcc -c b.cpp

[0] f:\tmp\a>

And this is a pretty old gcc...

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™.