Programming question about C++ Classes, need your help!

Programming question about C++ Classes, need your help!

HI,

This is a C++ programming question (not a SDL question).

I am writing a new game engine for Palm® platform.

I have several C++ Class structures:
VisualsCLASS.h
VisualsCLASS.cpp
ControlCLASS.h
ControlCLASS.cpp
SoundCLASS.h
SoundCLASS.cpp

All above classes are declared in game’s main CPP file: Project5.cpp

Problem now is that I wish to access a function from Visuals Class inside of
Sound Class,
but the compiler says the following:
Error : undefined identifier 'visualsCLASS’
SoundlCLASS.cpp line 110 visualsCLASS->DisplaySpriteBMP(2, 0, 0);

Now I am lost.

Can someone help me please!

Thanks in advance - SDL rocks!

Jesse
SLNTHERO at AOL.com (mailto:SLNTHERO at AOL.com)
http://www.SilentHeroProductions.com (http://www.SilentHeroProductions.com)

Hello !

This is a C++ programming question (not a SDL question).

Then please ask this question on a C++ related mailinglist.
There are lots of them out there.

CU

I have several C++ Class structures:
VisualsCLASS.h
VisualsCLASS.cpp
ControlCLASS.h
ControlCLASS.cpp
SoundCLASS.h
SoundCLASS.cpp

All above classes are declared in game’s main CPP file: Project5.cpp

Problem now is that I wish to access a function from Visuals Class inside
of Sound Class,
but the compiler says the following:
Error : undefined identifier 'visualsCLASS’
SoundlCLASS.cpp line 110 visualsCLASS->DisplaySpriteBMP(2, 0, 0);

For this you need to have member of type visualCLASS in soundCLASS or if
soundCLASS will inheritted from visualCLASS or if you will have method in
soundCLASS looks like this.

void set_video_interface( videoCLASS * )

or something else…

and ofcause you need to include visualCLASS.h in soundCLASS.h

But all of this is wrongly because you try to mix three unmixed thing on
this level of abstraction… In my opinion… I don’t see your code…–
Regards,
Igor Mironchick,
Intervale ©
#ICQ 492-597-570

Unless you need an actual VisualClass object to exist as part of your
SoundClass (which would make absolutely no sense), I believe the
preffered method is to declare the class in SoundClass’s header file,
like so(before you define your SoundClass class):

class VisualClass; //that’s it. It’s like a function declaration.
tells the compiler that it exists, but you’re not going to define it
just yet.

then, inside your SoundClass definition, have a pointer to a VisualClass object:

VisualClass * visualclass;

You can use a function(good idea) or constructor(bad idea), or
whatever to actually point the thing to the right object in your game,
by passing a reference (&visualclass) to the pointer in your
Soundclass.
You also must include your “VisualClass.h” file in the
"SoundClass.cpp", so your compiler can figure out exactly what your
trying to do with that class. I believe this method is preffered to
including unneccesary .h files in your header files - I know it has
worked better for me(I ran into big headaches trying to include my
header files inside of my other header files.)

That should get you on the right track. I use that sort of trick all
the time. pointers are wonderful!
-Dave OlsenOn 1/23/07, Igor Mironchick wrote:

I have several C++ Class structures:
VisualsCLASS.h
VisualsCLASS.cpp
ControlCLASS.h
ControlCLASS.cpp
SoundCLASS.h
SoundCLASS.cpp

All above classes are declared in game’s main CPP file: Project5.cpp

Problem now is that I wish to access a function from Visuals Class inside
of Sound Class,
but the compiler says the following:
Error : undefined identifier 'visualsCLASS’
SoundlCLASS.cpp line 110
visualsCLASS->DisplaySpriteBMP(2, 0, 0);

For this you need to have member of type visualCLASS in soundCLASS or if
soundCLASS will inheritted from visualCLASS or if you will have method in
soundCLASS looks like this.

void set_video_interface( videoCLASS * )

or something else…

and ofcause you need to include visualCLASS.h in soundCLASS.h

But all of this is wrongly because you try to mix three unmixed thing on
this level of abstraction… In my opinion… I don’t see your code…


Regards,
Igor Mironchick,
Intervale ©
#ICQ 492-597-570


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

David Olsen wrote:

pointers are wonderful!
-Dave Olsen

Especially when time come to delete all dynamicaly located objects and here
O-o-o-p-s CRASHES:) It’s JOKE…–
Regards,
Igor Mironchick,
Intervale ©
#ICQ 492-597-570

True, I’ve gotten myself into plenty of messes with dynamically
allocated arrays… But for a simple pointer like he’ll be using,
there’s nothing to worry about.
-DaveOn 1/24/07, Igor Mironchick wrote:

David Olsen wrote:

pointers are wonderful!
-Dave Olsen

Especially when time come to delete all dynamicaly located objects and here
O-o-o-p-s CRASHES:) It’s JOKE…


Regards,
Igor Mironchick,
Intervale ©
#ICQ 492-597-570


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks to all SDL mailing list member, I have it working now.

What I needed was very simple:

extern VisualCLASS* visualCLASS;

at top of SoundCLASS.cpp

Thanks again!

Jesse
SLNTHERO at AOL.com (mailto:SLNTHERO at AOL.com)
http://www.SilentHeroProductions.com (http://www.SilentHeroProductions.com)

In a message dated 1/24/2007 12:41:31 P.M. Eastern Standard Time,
jolynsbass at gmail.com writes:

Unless you need an actual VisualClass object to exist as part of your
SoundClass (which would make absolutely no sense), I believe the
preffered method is to declare the class in SoundClass’s header file,
like so(before you define your SoundClass class):

class VisualClass; //that’s it. It’s like a function declaration.
tells the compiler that it exists, but you’re not going to define it
just yet.

then, inside your SoundClass definition, have a pointer to a VisualClass
object:

VisualClass * visualclass;

You can use a function(good idea) or constructor(bad idea), or
whatever to actually point the thing to the right object in your game,
by passing a reference (&visualclass) to the pointer in your
Soundclass.
You also must include your “VisualClass.h” file in the
"SoundClass.cpp", so your compiler can figure out exactly what your
trying to do with that class. I believe this method is preffered to
including unneccesary .h files in your header files - I know it has
worked better for me(I ran into big headaches trying to include my
header files inside of my other header files.)

That should get you on the right track. I use that sort of trick all
the time. pointers are wonderful!
-Dave OlsenOn 1/23/07, Igor Mironchick wrote:

I have several C++ Class structures:
VisualsCLASS.h
VisualsCLASS.cpp
ControlCLASS.h
ControlCLASS.cpp
SoundCLASS.h
SoundCLASS.cpp

All above classes are declared in game’s main CPP file: Project5.cpp

Problem now is that I wish to access a function from Visuals Class inside
of Sound Class,
but the compiler says the following:
Error : undefined identifier 'visualsCLASS’
SoundlCLASS.cpp line 110
visualsCLASS->DisplaySpriteBMP(2, 0, 0);

For this you need to have member of type visualCLASS in soundCLASS or if
soundCLASS will inheritted from visualCLASS or if you will have method in
soundCLASS looks like this.

void set_video_interface( videoCLASS * )

or something else…

and ofcause you need to include visualCLASS.h in soundCLASS.h

But all of this is wrongly because you try to mix three unmixed thing on
this level of abstraction… In my opinion… I don’t see your code…


Regards,
Igor Mironchick,
Intervale ©
#ICQ 492-597-570


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

2007/1/25, SlntHero at aol.com :

Thanks to all SDL mailing list member, I have it working now.

What I needed was very simple:

extern VisualCLASS* visualCLASS;

at top of SoundCLASS.cpp
Thanks again!

Looks like a global variable?!?!
H-m-m-m…–
Regards,
Igor Mironchick,
Intervale ©
#ICQ 492-597-570