Linking Problems

Started by
11 comments, last by EvilNando 19 years, 9 months ago
hello im having some troubles linking my classes together what im doing is this System.h -> all globals defines and includes are here Application.h -> links to System.h CDirect3D.h -> links to System.h i must say also that Application has a member of type Cdirect3D that is instatiated at the constructor and CDirect3d has a member *WindowApp pointing to a Application class object that is also generated at the constructor i cant compile this thing and i dont know what im doing wrong any help? [edit] moved to the begginers forum [/edit]
Advertisement
What errors are you getting exactly? Also, if would help if you posted some code.
are you using #ifndef and extern and things like that in your header files?
______________________________________________________________________________________With the flesh of a cow.
no im not using none of those

heres some code
//**************************************************/// CApplication.h // Class responsible for bulding the window framework // for the DirectX Game// Armando Alva@2004//**************************************************///**************************************************/#pragma once// Exclude rarely-used stuff from Windows headers#define WIN32_LEAN_AND_MEAN		// Link in the required libraries#pragma comment(lib, "d3d9.lib")#pragma comment(lib, "d3dx9.lib")#pragma comment(lib, "winmm.lib")#include <d3dx9.h>#include <windows.h>#include "CDirect3D.h"//**************************************************/class CApplication{public:		/* Constructor */     CApplication(void);	/* Destructor */	virtual ~CApplication(void);	/* Message Procedures */	virtual LRESULT WINAPI MessageProcedure(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);	/* Start all CApplication systems */ 	void Run();protected:	/* This Function Creates the Window */	bool MakeWindow(int iWidth, int iHeight, bool bWindowed);	/* Main Loop Function */	void GameLoop(void);	virtual bool FirstInitialize() { return TRUE; }     // Called at the beginning    virtual bool FinalCleanup() { return TRUE; }        // Called at the end    virtual int  PreRender();							// Called before rendering    virtual int  Render();								// Called after rendering 		HWND m_hWnd;			// Handle of the Window CApplication	bool m_bWindowed;       // Is the CApplication windowed or fullscreen    UINT m_iWndWidth;       // Windowed width    UINT m_iWndHeight;      // Windowed height	bool m_bActive;			// Flag to check if window is active	bool m_bPaused;			// Flag to check if window is paused	bool m_bAlive;			// Flag to check if window is alive    char m_strTitle[128];		// Our CApplications title    char m_strClass[128];		// Our CApplications unique class name		// DIRECT3D ENGINE CLASS //	CDirect3D*	CD3DEngine;			// DIRECT3D ENGINE CLASS //};


//**************************************************/// CApplication.cpp// Declarations for Applciation.h//// Armando Alva@2004//**************************************************/#include "Application.h"// This header is so we can assign this message handler to the WNDCLASSEX structureLRESULT WINAPI MainMessageProcedure(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);CApplication::CApplication(void){	// Initiliaze all Class Members //		m_bWindowed		= true;	m_hWnd			= NULL;	m_iWndWidth		= 800;	m_iWndHeight	= 600;	m_bActive		= true;	m_bAlive		= true;		m_bPaused		= false;	CD3DEngine		= NULL;	strcpy(m_strClass, "WindowsClass");	strcpy(m_strTitle, "Game Program");	// Create the 3D Engine Class //	CD3DEngine = new CDirect3D;	}// PreRender Function //int CApplication::PreRender(void){		if(!CD3DEngine->PreRender3D())	{		return 0;	}	return 1;}// Render Function //int CApplication::Render(void){	if(!CD3DEngine->Render3D())	{		return 0;	}	return 1;}


//**************************************************/// 3DEngine.h // Class responsible for all the D3D initialization // for the DirectX Game// Armando Alva@2004//**************************************************/#include "Application.h"class CDirect3D{public:		/* Constructor & Destructor */     CDirect3D(CApplication& AppClass);	~CDirect3D(void);		/* Start the whole 3D process */	int Initialize3D(void);		/* End the whole 3D process */	void Terminate3D(void);   	/* Prerender Settings */	int PreRender3D(void);	/* Render Settings */	int Render3D(void);private:			HRESULT					m_hResult;		/* Here its stored any error msgs */		IDirect3D9*				m_pD3DObject;	/* DirectX9 Object */		IDirect3DDevice9*		m_pD3DDevice;	/* DirectX9 Device */		D3DFORMAT				m_D3DFormat;	/* DirectX9 Format */	D3DPRESENT_PARAMETERS	m_D3DPP;		/* DirectX9 Present Parameters */		CApplication*			m_pAppClass;	/* Pointer to the window class */	};


//**************************************************/// 3DEngine.cpp// Declarations for 3DEngine.h// // Armando Alva@2004//**************************************************/#include "Application.h"#include "CDirect3D.h"/* Constructor *///**************************************************/CDirect3D::CDirect3D(CApplication& AppClass){	// Initialize Members		m_D3DFormat		= D3DFMT_R5G6B5;	m_pD3DDevice	= NULL;	m_pD3DObject	= NULL;	m_pAppClass		= AppClass;		ZeroMemory(&m_D3DPP, sizeof(D3DPRESENT_PARAMETERS));	// Set the address of the main application handle here}/* Initialize3D *///**************************************************/int CDirect3D::Initialize3D(void){	m_pD3DObject = Direct3DCreate9( D3D_SDK_VERSION );		if(!m_pD3DObject)	{		MessageBox(m_pAppClass->m_hWnd, "Direct3DCreate9 Failed!", "Error", MB_OK);		return 0;	}		// D3DPRESENT PARAMETERS INIT	m_D3DPP.BackBufferCount		= 1;					// A single back buffer is needed here	m_D3DPP.MultiSampleType		= D3DMULTISAMPLE_NONE;	// No multisampling	m_D3DPP.MultiSampleQuality	= 0;					// No multisampling	m_D3DPP.SwapEffect			= D3DSWAPEFFECT_DISCARD;// Throw away processed frames they are not needed	m_D3DPP.hDeviceWindow		= m_pAppClass->m_hWnd;	// Window handle	m_D3DPP.Flags				= 0;					// No Flags to set	m_D3DPP.FullScreen_RefreshRateInHz	= D3DPRESENT_RATE_DEFAULT; //Default Refresh Rate	m_D3DPP.PresentationInterval= D3DPRESENT_INTERVAL_DEFAULT;   //Default Presentation rate	m_D3DPP.BackBufferFormat	= m_D3DFormat;			// Bytes used for the display	m_D3DPP.EnableAutoDepthStencil = FALSE;				// No depth stencil buffer	if(m_pAppClass->m_bWindowed)	{		m_D3DPP.Windowed		= true;					// Set windowed mode ON	}	else	{        m_D3DPP.Windowed		= false;		m_D3DPP.BackBufferWidth = 800;		m_D3DPP.BackBufferHeight= 600;	}	// Now create the device	m_hResult = m_pD3DObject->CreateDevice(D3DADAPTER_DEFAULT,		// The default adapter										   D3DDEVTYPE_HAL,			// Use Hardware Acceleration										   m_AppClass->m_hWnd,				// Handle to the application										   D3DCREATE_SOFTWARE_VERTEXPROCESSING,// process vertex in software for compatibility										   &m_D3DPP,				// The app PRESENT_PARAMETERS										   &m_pD3DDevice);			// Now pointing to the new created device	if(FAILED(m_hResult))	{		MessageBox(m_AppClass->m_hWnd, "CreateDevice Failed!", "Error", MB_OK);		return 0;	}	return 1;}/* Terminate 3D *///**************************************************/void CDirect3D::Terminate3D(void){	// check for a valid D3D device	if(m_pD3DObject)	{		m_pD3DObject->Release();				// NULL the pointer just to be safe		m_pD3DObject = NULL;	}}


the errors im getting ...


CDirect3D.h(41): error C2501: 'CDirect3D::Application' : missing storage-class or type specifiers




CDirect3D.h(41): error C2501: 'CDirect3D::CApplication' : missing storage-class or type specifiers
CDirect3D.h(41): error C2501: 'CDirect3D::m_pAppClass' : missing storage-class or type specifiers
CDirect3D.h(12): error C2011: 'CDirect3D' : 'class' type redefinition
CDirect3D.h(12) : see declaration of 'CDirect3D'
CDirect3D.cpp(15): error C2511: 'CDirect3D::CDirect3D(CApplication &)' : overloaded member function not found in 'CDirect3D'

amongs others

thanks !
This is what I see for starters:

You have an include problem. You see, in C/C++, the preprocessor just inserts anything (dumps) that is included into the compilation unit. Also, C needs to know what a structure is before it is first used....

SO heres what your problem seems to be:

First, CDirect3D.cpp (according to the compiler message, though you have it called 3DEngine.cpp in the source listing) is what is currently compiling (compilation unit). THe first thing it sees is #include "application.h" ... SO it dumps that into current CU (compilation unit) and starts parsin it... So now, we are processing the pragma's in that header, which is fine... But the mess comes when the #include CDirect.h is found.

That now gets dumped into the CU. Ok... SO we now process that part. Now, the first thing that is called from CDirect.h is #include Application ****** Here is the Problem ******. Since this header file was already (semi processed anyway) and was told to pragma once... CApplication has yet to be defined!

So of course you will get errors that mean that CApplication is not a type.
Oh... As for a solution to your problem: This is what you want :)

Best of luck
Quote:Original post by pjcast
This is what I see for starters:

You have an include problem. You see, in C/C++, the preprocessor just inserts anything (dumps) that is included into the compilation unit. Also, C needs to know what a structure is before it is first used....

SO heres what your problem seems to be:

First, CDirect3D.cpp (according to the compiler message, though you have it called 3DEngine.cpp in the source listing) is what is currently compiling (compilation unit). THe first thing it sees is #include "application.h" ... SO it dumps that into current CU (compilation unit) and starts parsin it... So now, we are processing the pragma's in that header, which is fine... But the mess comes when the #include CDirect.h is found.

That now gets dumped into the CU. Ok... SO we now process that part. Now, the first thing that is called from CDirect.h is #include Application ****** Here is the Problem ******. Since this header file was already (semi processed anyway) and was told to pragma once... CApplication has yet to be defined!

So of course you will get errors that mean that CApplication is not a type.


So what do you think I can do to solve that?
Check out the link I posted.

But, for a quick rundown:

Be careful having your own include files including other include files. For instance:

If class A needs to know about class B, and class B needs to know about class A, forward declare one of the classes instead of including the header file.

So, in your case:

In appliation.h, remove the include CDirect3d.h line . Replace it with:

class CDirect3D;

And in CDirect3D.h, remove the #include Application.h, and add this some where above your class definition:

class CApplication;

Now, because you only use pointers in your header files, this will work perfectly for you. But, in both your source files, you will need to include the CDirect.h & CApplication.h headers.
thank you so much
i now figured what to do
but now ive stumbled into another trouble

how u solve this

example:

for my game im using 2 classes right now

1. Is CApplication, in charge of registering the window and creating it

2. Is CDirect3D, in charge of creating the display device and locking the surface

now

what ive been trying to the whole day is this

put a member in CApplication of type CDirect3D so when the window is created i can make a call to the 3drendering stuff

but since all D3D stuff needs a handle to a window on the CDirect3D class I need a pointer to a CApplication class

well what ive been trying to do is create a Direct3D class at the constructor of the CApplication

and make the constructor of the CDirect3D class to take an address of CApplication as a parameter

but its not working

can u help me?
I'm all about helping ;)

Ok, you say what you are trying to do isn't working. So I take it you can compile and link, but you just don't know how to call your overloaded constructor ( CDirect3D::CDirect3D(CApplication &pApp) )that takes an Application reference?

Where you can do that, is in your constructor. You have this right now:
CD3DEngine = new CDirect3D;

But you should make it:
CD3DEngine = new CDirect3D( this );

That will call the constructor taking a CApplication class.
Using the "this" pointer.

And just for your reference, the compiler may throw a warning at you about using the this pointer before CApplication is fully constructed; however, since you are only saving it and not doing anything dangerous with it, it is safe to ignore.

CApplication::CApplication(void){	// Initiliaze all Class Members //		m_bWindowed		= true;	m_hWnd			= NULL;	m_iWndWidth		= 800;	m_iWndHeight	= 600;	m_bActive		= true;	m_bAlive		= true;		m_bPaused		= false;	CD3DEngine		= NULL;	strcpy(m_strClass, "WindowsClass");	strcpy(m_strTitle, "Game Program");	// Create the 3D Engine Class //	CD3DEngine = new CDirect3D(this);	}

This topic is closed to new replies.

Advertisement