Boy, that dictionary is paying off
Anyways.
Heres my problem:
I have a custom class I created called CTexture as well as a custom class called CSprite. What I need is for multiple CSprite classes to point to a SINGLE CTexture class.
Heres my two classes.
Code:class CTexture { public: CTexture(); ~CTexture(); LPDIRECT3DTEXTURE9 GetTexture(); int GetWidth(); int GetHeight(); bool LoadTexture(char *filename, int width, int height, LPDIRECT3DDEVICE9 device); private: LPDIRECT3DTEXTURE9 m_texture; int m_width; int m_height; };I was just wondering if my line in RED is correct or not. I'm pretty sure it is and by cycling through the debugger abit it appears to do what I want it to do. However, since this wasn't my initial solution I just wanted to get a second opinion if this is proper or not.Code:struct SFrame { int frameNum; RECT frameBoundary; D3DXVECTOR3 center; SFrame *nextFrame; }; class CSprite { public: CSprite(); ~CSprite(); bool SetTexture(CTexture &texture); void NewFrame(int frameWidth, int frameHeight, int startPixelX, int startPixelY); bool Draw(int frameNum, D3DXVECTOR3 position, LPDIRECT3DDEVICE9 device); private: CTexture *m_Texture; SFrame *m_FirstFrame; LPD3DXSPRITE m_Sprite; int m_TotalFrames; }; bool CSprite::SetTexture(CTexture &texture) { if(!texture.GetTexture()) return false; m_Texture = &texture; return true; }
My initial solution was:
But it was complaining about "=" because I didn't overload the "=" for CTexture class. If I created a "=" function and copied variables from texture to m_Texture that would create a copy and not a pointer right?Code:m_Texture = texture;
Because elsewhere in my code I have:
And it works fine.. seems like a similar circumstance except temp & m_FirstFrame are referring to a STRUCT while in the first case I had pointers to a CLASS.. Why does the first example require a & but the second case does not complain about a need for overload "=" operator.Code:SFrame *m_FirstFrame; SFrame *temp; temp = m_FirstFrame;
Is this because a class has private while everything in a struct is public?
Thnx for any clarification.



LinkBack URL
About LinkBacks




. What a shame again!