Sign in to follow this  
Enerjak

Destructor mismatch

Recommended Posts

everytime i try ti make a class with constructors and Destructors, it messed up. it tells me that the distructor is a mismatch ort what ever. here is my code.

class Cor_CDirect3D9Renderer
{
public:
	int		Cor_Direct3D9Renderer();
	virtual ~Cor_Direct3D9Renderer();
	int		Cor_CDirect3DRenderer9(HWND hwnd, int width, int height, bool fullscreen);
	void	Cor_Sync();
	LPDIRECT3D9* Cor_ReturnDirect3D9();
	LPDIRECT3DDEVICE9* Cor_ReturnDirect3DDevice9();
	LPDIRECT3DSURFACE9* Cor_ReturnBackBuffer();
	D3DPRESENT_PARAMETERS* Cor_ReturnPresentParams();
private:
	LPDIRECT3D9 Cor_Direct3D9;
	LPDIRECT3DDEVICE9 Cor_Direct3DDevice9;
	D3DPRESENT_PARAMETERS Cor_PresentParams;
	LPDIRECT3DSURFACE9 Cor_BackBuffer;
};



1>c:\documents and settings\directx\my documents\visual studio 2008\projects\cor_direct3d9\cor_direct3d9\Cor_CDirect3D9.h(15) : error C2523: 'Cor_CDirect3D9Renderer::~Cor_Direct3D9Renderer' : destructor tag mismatch
1>.\Cor.cpp(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int


I think i figured out how to get rid of Access violations. just initialize every variable in the class in the constructor to be NULL, that'll get rid of the access violations, maybe. Anyways, can you guys help me with this annoying error concerning the destructor?

Share this post


Link to post
Share on other sites
Quote:
Original post by Enerjak
I think i figured out how to get rid of Access violations. just initialize every variable in the class in the constructor to be NULL, that'll get rid of the access violations, maybe.

If your variables are pointers, then yes you should initialize them to NULL so that you can tell whether it actually points to something or not.

If try to use a pointer when it's not actually pointer to something, you will get an access violation error. People usually use NULL (A.K.A. 0) as an 'invalid pointer value' so that before they use the pointer, they can check if it's valid.
e.g.
//Good practice:
MyClass* pointer = 0;
...
if( randomThing == true )
pointer = new MyClass;
...
if( pointer != 0 )//it's not NULL, so I assume it's pointing to a new MyClass
pointer->doStuff();//This should never cause an error, because we know the pointer is valid

//Bad Practice:
MyClass* pointer;//not initialized, so it could be anything, such as 0xBAADF00D
...
if( randomThing == true )
pointer = new MyClass;
...
//There's no way for me to know if it's actually pointing to a new MyClass, or if it's just uninitialized!
if( pointer != 0 )//it wasn't initialized to 0, so this will almost always return true, even if the pointer isn't valid
pointer->doStuff();//I hope this doesn't cause an access violation!!!





[Edited by - Hodgman on January 31, 2008 6:16:14 PM]

Share this post


Link to post
Share on other sites
Lo and behold, the class-and-method-name clutter has disappeared!

namespace Core
{
class Direct3D9Renderer
{
public:
int Direct3D9Renderer();
virtual ~Direct3D9Renderer();
int Direct3DRenderer9(HWND hwnd, int width, int height, bool fullscreen);
void Sync();
LPDIRECT3D9* ReturnDirect3D9();
LPDIRECT3DDEVICE9* ReturnDirect3DDevice9();
LPDIRECT3DSURFACE9* ReturnBackBuffer();
D3DPRESENT_PARAMETERS* ReturnPresentParams();
private:
LPDIRECT3D9 Direct3D9;
LPDIRECT3DDEVICE9 Direct3DDevice9;
D3DPRESENT_PARAMETERS PresentParams;
LPDIRECT3DSURFACE9 BackBuffer;
};
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this