Object sending it's own address?

Started by
3 comments, last by IADaveMark 21 years, 2 months ago
Ok... I''m missing something really bloody simple here. I have a class object that needs to send it''s own pointer address as a parameter to a function from another class. How would I write that? Dave Mark - President and Lead Designer Intrinsic Algorithm - "Reducing the world to mathematical equations!"

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Advertisement
Use the "this" keyword.
--------------------Nicholas Skapuraskapura.2@wright.eduhttp://skap.8k.comAIM: skap35
Hmm. Use the "this" pointer? Or are you doing something more complex?

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
OK... so...

cOtherClass
...
void HeresMyPointer(cMyClass* pointer);

****************

cMyClass
...
HeresMyPointer(this);

Dave Mark - President and Lead Designer
Intrinsic Algorithm - "Reducing the world to mathematical equations!"

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Right. Just be sure that you avoid circular references by using a forward reference in whichever of the classes makes sense to do so. In other words, in a class that can only use pointers, use

class CMyClass;

previous to your class declaration in CMyClass2. Then you can do an #include "MyClass.h" in CMyClass2.cpp, but you''re not allowed to use anything but pointers to CMyClass in CMyClass2 (CMyClass, which will be doing a #include "MyClass2.h" in the header, but will not require a "class CMyClass2;", will not have any such restrictions.

That way, you avoid getting undeclared errors everywhere, due to the fact that your classes apparently know about each other in some fashion.

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~

This topic is closed to new replies.

Advertisement