Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Baloogan

c++ programming dellima(sp)

This topic is 5821 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

say i had 2 classes class CA { int A; int B; CB C; } class CB { // needs int A ( from class CA) but class CA needs to have class CB int A; } The way I tryed to fix this is : CA = CEngine CB = CFontEngine
  

class CEngine  
{
public:
	CEngine();
	virtual ~CEngine();
	bool Direct3DInit();
	void UpdateScene();
	void DrawScene();
	void Direct3DRelease();
	CWindow Window;
	CDirect3D Direct3D;
	CFontEngine Font;
	CVertexBuffer Vertices;
	CVertexBuffer ProcessedVertices;
	CTexture Texture;
};

CEngine::CEngine()
(line 39){
(line 40)	Font.CFontEngine(&Direct3D);

}



class CFontEngine
{
public:
	CFontEngine(CDirect3D *Directi);
	~CFontEngine();
	HRESULT Initialize(HFONT hFont, D3DCOLOR FontColor);
	HRESULT OutputText(char *pString, int x, int y);
	CDirect3D *Direct; // needs this...

	D3DCOLOR m_FontColor;
	int m_Align;
	LPD3DXFONT m_pFont;
	RECT m_FontRect;
	BOOL m_bInitialized;

	
};

CFontEngine::CFontEngine(CDirect3D *Directi)
{
	*Direct = *Directi;
}

  
This doesnt work... errors Engine.cpp(39) : error C2512: ''CFontEngine'' : no appropriate default constructor available (40) : error C2274: ''function-style cast'' : illegal as right side of ''.'' operator Engine.cpp(40) : error C2100: illegal indirection how can I get this to work?

Share this post


Link to post
Share on other sites
Advertisement
Pointers and forward referencing:

// forward reference
class CB;
 
class CA
{
// blah
CB * cb;
};
 
class CB
{
// blah
CA * ca;
};

Enjoy.

Share this post


Link to post
Share on other sites
Just stick a forward declaration in both, or make sure you include the header file with the forward declaration in your project before including the other header (should work, though I haven''t tested it).

Share this post


Link to post
Share on other sites
I tryed that and got 6 errors about ''Font uses undefined class CFontEngine'' ... , I dont think that it can be done that way, could someone plz help me understand useing pointers and constructures in classes???? eg:


  

class C
{
int a;
}
class B
{
B(C data);
~B();
}

class A
{
A();
~A();
B clsB;
}






how can I have when A is constructed, can pass variables to B''s construter?????

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!