Advertisement

Class Trouble

Started by April 27, 2001 11:48 AM
4 comments, last by reaptide 23 years, 9 months ago
Hello Everyone, I''m having a problem which is driving me nuts. This is the first time that I am using classes in my application and I''m having trouble with the snippet of code below. My compiler (MSVC++ 6) keeps telling me that the constructor is not allowed a return type, yet my constructor doesn''t seem to be returning anything. Does anyone know what is going on?
  
CDirect3D::CDirect3D()
{
	lpD3D		= NULL;
	lpD3DDevice = NULL;
}
  
Signatures? We don''t need no stinking signatures!
I think your problem is that the compiler defaults to an interger return type. Declaring the following:

function_x()
{
}

says function x returns an int.

but to return nothing
you need a void return type.


in C++ constructors have to have a void return type.
the proper version of your code should look like this

class myClass {
public:
void myClass(); //construtor declaration

}

actual implementation:

void myClass::myClass(){
//do anything here except return a value.
}
Advertisement
Well, if there is actually a "class CDirect3D" defined, then the constructor will not default to an int return-type.

I think you need to provide more info, reaptide, because the code as shown is correct.

Also, make sure you aren't specifying any return type in your actual class declaration.

// CHRIS


Edited by - win32mfc on April 27, 2001 1:26:18 PM
// CHRIS [win32mfc]
Thanks for the responses guys. Unfortunatly MSVC++ won''t let you declare a return type for a constructor, so declaring a void in the constructor won''t work.

As for additional info, here it is, hope it helps:

  // CDirect3D.h//---------------------------------------------------------------// INCLUDES //---------------------------------------------------------------#include <d3d8.h>#include <d3dx8.h>//---------------------------------------------------------------// CLASS DEFINITION//---------------------------------------------------------------class CDirect3D{public:	CDirect3D();	~CDirect3D();		int Init(HWND hWnd, int ScreenWidth, int ScreenHeight);	int BeginDraw();	int EndDraw();	int Shutdown();private:	LPDIRECT3D8       lpD3D;	LPDIRECT3DDEVICE8 lpD3DDevice;}// CDirect3D.cpp//---------------------------------------------------------------// INCLUDES //---------------------------------------------------------------#include <d3d8.h>#include <d3dx8.h>#include "D3DUtils.h"//---------------------------------------------------------------// Name: CDirect3D()// Desc: Constructor for the Class//---------------------------------------------------------------CDirect3D::CDirect3D(){	lpD3D	    = NULL;	lpD3DDevice = NULL;}//---------------------------------------------------------------// Name: ~CDirect3D()// Desc: Destroyer for the Class//---------------------------------------------------------------CDirect3D::~CDirect3D(){	lpD3D	    = NULL;	lpD3DDevice = NULL;}  


That''s the full listing for my CDirect3D Class.



Signatures? We don''t need no stinking signatures!
yo are simjply missing a semicolon after the last breacket of the class...... };
*Smacks himself Silly*

I can''t believe I missed that. Forgot that classes are really a lot like structures.

Thanks a lot acw83 it works great now.



Signatures? We don''t need no stinking signatures!

This topic is closed to new replies.

Advertisement