Skip to main content
gamedev.net
🔒 Locked

Pointers

Started by Aidamina 9 replies 650+ views
Original Post
Aidamina
Aidamina
I created a node class, but i got a problem since i want the node class integrated in my engine and i wanna link a node to every class eg: nodes: Root->Child->Child-> etc etc Engine->Rendering->Gui etc etc My question is: How do i link them. I can't create a pointer to the classes because the Rendering class isnt the same as the Engine class and because the nodes are uniform i can only point to one type of class from within a node. Any suggestions?
-->My Site<--
Illco
Illco
If you want do this you should make all those classes inherit from a basic node class. Then you can use it as such only without the nice names (rather GetParent(), GetChild(), etc, or you must create them explicitly). But why would you want it? There is no such parent/child relationship between an engine and its renderer or between a renderer and the GUI. Such relationships are reflected better by different designs.


Greetz,

Illco
Aidamina
Aidamina
Well its more like a tree, it shouldnt inherit anything from the parent, it should just be able to acces the parent and child directly.
-->My Site<--
Illco
Illco
If so you can store a pointer in the class:
class CEngine{  CRenderer* m_pRenderer;}
Aidamina
Aidamina
yeah but how would m_pRenderer acces Cengine?
-->My Site<--
Illco
Illco
Quite similar, although I get the feeling I'm missing your point:
class CRenderer{  CEngine* m_pEngine;}


You could construct it like this:
CEngine* pEngine = new CEngine();CEngine::CEngine(){  m_pRenderer = new CRenderer( this );}CRenderer::CRenderer( CEngine* pEngine){  m_pEngine = pEngine;}
SiliconMunky
SiliconMunky
Quote:
Original post by Illco
Quite similar, although I get the feeling I'm missing your point:
class CRenderer{  CEngine* m_pEngine;}


You could construct it like this:
CEngine* pEngine = new CEngine();CEngine::CEngine(){  m_pRenderer = new CRenderer( this );}CRenderer::CRenderer( CRenderer* pRenderer ){  m_pEngine = pRenderer;}



I think you've got a typo
shouldn't it be
CRenderer::CRenderer( CEngine* pEngine){  m_pEngine = pEngine;}

?
Illco
Illco
Well that's what it says... :-)
Aidamina
Aidamina
Yeah thats a nice possibility.

Is it possible to point to any class like create some unbound pointer.

Like:

AnyClass * ptr;

ptr = new DefinedClass();

Or am i just being a noob :P
-->My Site<--
Enigma
Enigma
Well, you can, but 99 times out of 100 you don't want to. Think about it. If the pointer is untyped then how would you use it? Every time you wanted to use it you'd have to cast it to the correct type. And if you were ever wrong...

Enigma
Aidamina
Aidamina
Yeah ok i see your point.

Ratings++
Illco, Enigma

Thx guys cleared up a lot
Although i still want to use nodes in my engines
I see i'd rather not do that.
-->My Site<--

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.