Problem with Method

Started by
10 comments, last by Moe Szyslack 15 years, 7 months ago
Can't really solve this with the given code, but save yourself a lot of grief and just do this:

class Sprite{public:    // snip (but use the constructor instead of Initialise)    LPD3DXSPRITE GetSprite(){ return m_Sprite; }};class Menu{public:    // snip    void Render(Sprite &S){ LPD3DXSPRITE Temp=S.GetSprite(); DoStuffWithIt(Temp); }};


Or in other words, stop trying to make the sprite pointer exist everywhere and just pass the parameters you need to the functions that use them.

Even better, hide the implementation detail of D3DXSprite behind a public interface in your Sprite class and use this interface everywhere else. But pass Sprite as a parameter to Menu's render function. Menu's SetOptionText() method (random example picked from air) does not need to access rendering stuff so should not have access to the rendering stuff.
Advertisement
Ok, I will try it that way. Thanks to everyone who answered.

This topic is closed to new replies.

Advertisement