I thought constructors had no return types?!

Started by
14 comments, last by Paulius Maruska 17 years, 8 months ago
Hello there, When I tried to compile the code from my engine I got the error error C4430: missing type specifier - int assumed. Note: C++ does not support default-int And it points to this piece of code (actually, the '{'):
cInput::cInput()
{
	m_pDI->Clear();
}
How come this error turns up? I've always thought constructors and destructors have no return type, and my code has always worked... -Stenny
What do I expect? A young man's quest to defeat an evil sorceror while discovering the truth of his origins. A plucky youngster attended by her brutish guardian. A powerful artifact which has been broken into a small number of artifactlets distributed around the world.What do I want? Fewer damn cliches. - Sneftel
Advertisement
The error is probably somewhere before your constructor, such as a missing brace or semi-colon.
It isn't recognizing cInput() as a constructor. There are several reasons this might be the case...most notably, did you include the proper header?

CM
Your problem most likely exists elsewhere. Check your header files sometimes when there is an error in them it wont get that and place the error in the first cpp file. The easy way to check for that is to just move the function last and see if he complains on the same function again.
Plane9 - Home of the free scene based music visualizer and screensaver
Ok, I'll give you guys the complete pipeline:

Everything starts in WinMain.cpp:

#include "Core_Global.h"HWND		g_hWnd;HINSTANCE	g_hInst;#define		WNDWIDTH 400#define		WNDHEIGHT 400#define		WNDTYPE WS_OVERLAPPEDWINDOWconst char	g_szClass[] = "EnumClass";...


Let's have a look at Core_Global.h:
// file: Core_Global.h //#ifndef _CORE_GLOBAL_H_#define _CORE_GLOBAL_H_#define DIRECTINPUT_VERSION 0x080#include <windows.h>#include <stdio.h>#include <d3d9.h>#include <d3dx9.h>#include <dmusici.h>#include <dsound.h>#include <dplay8.h>#include <dpaddr.h>#include <dinput.h>#include <dshow.h>#include "Core_Input.h"#endif


It includes all the DirectX headers and my own, Core_Input:

// file: Core_Input.h //#ifndef _CORE_INPUT_H_#define _CORE_INPUT_H_#define ReleaseCOM(x) if(x) { x->Release(); x = NULL; }enum InputDevices{	NONE,	KEYBOARD,	MOUSE,	JOYSTICK};#define BUTTON_RELEASED    FALSE#define BUTTON_PRESSED      TRUE#define BUTTON_UNLOCKED    FALSE#define BUTTON_LOCKED       TRUE#define MOUSE_LBUTTON          0#define MOUSE_RBUTTON          1#define MOUSE_MBUTTON          2#define JOYSTICK_BUTTON0       0#define JOYSTICK_BUTTON1       1#define JOYSTICK_BUTTON2       2#define JOYSTICK_BUTTON3       3#define JOYSTICK_BUTTON4       4#define JOYSTICK_BUTTON5       5class cInput;class cInputDevice;class cInput{protected:	HWND			m_hWnd;	IDirectInput8	*m_pDI;public:	cInput();	~cInput();	IDirectInput8	*GetDirectInputCOM();	HWND			GethWnd();	BOOL			Init(HWND hWnd, HINSTANCE hInst);	BOOL			Shutdown();};class cInputDevice{protected:	cInput				*m_Input;	short				*m_Type; // MOUSE, KEYBOARD or JOYSTICK	IDirectInputDevice8	*m_pDIDevice;	BOOL				m_Windowed;	BOOL				m_Locks[256];	char				m_State[256];	DIMOUSESTATE		*m_MouseState;	DIJOYSTATE			*m_JoystickState;	long				m_XPos, m_YPos;	static BOOL CALLBACK EnumJoysticks(LPCDIDEVICEINSTANCE pdInst, LPVOID pvRef);public:	cInputDevice();	~cInputDevice();	IDirectInputDevice8	*DeviceCOM();    BOOL Create(cInput *Input, short Type, BOOL Windowed = TRUE);    BOOL Free();    BOOL Clear();    BOOL Read();    BOOL Acquire(BOOL Active = TRUE);    BOOL GetLock(char Num);    BOOL SetLock(char Num, BOOL State = TRUE);    long GetXPos();    BOOL SetXPos(long XPos);    long GetYPos();    BOOL SetYPos(long YPos);    long GetXDelta();    long GetYDelta();    // Keyboard specific functions    BOOL  GetKeyState(char Num);    BOOL  SetKeyState(char Num, BOOL State);    BOOL  GetPureKeyState(char Num);    short GetKeypress(long TimeOut = 0);    long  GetNumKeyPresses();    long  GetNumPureKeyPresses();    // Mouse/Joystick specific functions    BOOL  GetButtonState(char Num);    BOOL  SetButtonState(char Num, BOOL State);    BOOL  GetPureButtonState(char Num);    long  GetNumButtonPresses();    long  GetNumPureButtonPresses();};#endif


All the functions of these classes are defined inside Core_Input.cpp:
// file: Core_Global.cpp ////////////////////// cInput Class ////////////////////cInput::cInput(){	m_pDI->Clear();}cInput::~cInput(){	ShutDown();}HWND cInput::GethWnd(){	return m_hWnd;}IDirectInput8 *cInput::GetDirectInputCOM(){...


And there we are at the place of the error. So somewhere in these parts of the code should the error be...I've been searching my ass of and I think it's something rather stupid[grin].

-Stenny

---EDIT---
It also throws up the error:

error C2227: left of '->Clear' must point to class/struct/union/generic type, so the class cInput is probably not defined/declared correctly...
What do I expect? A young man's quest to defeat an evil sorceror while discovering the truth of his origins. A plucky youngster attended by her brutish guardian. A powerful artifact which has been broken into a small number of artifactlets distributed around the world.What do I want? Fewer damn cliches. - Sneftel
Core_Input.cpp does not know that cInput is a class because you have not included the appropriate header from Core_Input.cpp. Assuming the code you posted is accurate, at least.
As suggested, you are not including the proper headers. Core_Input.cpp needs to include Core_Input.h, or else it won't know anything about cInput.

CM
I thought including a header in one cpp file was enough...But thanks[smile], let's see if it works...

---EDIT---
No it didn't. I actually got 165 errors more then I had before...More of them default -int ones.

-Stenny
What do I expect? A young man's quest to defeat an evil sorceror while discovering the truth of his origins. A plucky youngster attended by her brutish guardian. A powerful artifact which has been broken into a small number of artifactlets distributed around the world.What do I want? Fewer damn cliches. - Sneftel
Quote:Original post by stenny
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Are you sure the compiler is expecting C++ code? From the looks of that error message, it seems as if the compiler thinks it deals with C code.
[s]--------------------------------------------------------[/s]chromecode.com - software with source code
Yes, I'm sure...I'm usingMicrosoft Visual Studio C++ EE with the same stats I always work with.

-Stenny
What do I expect? A young man's quest to defeat an evil sorceror while discovering the truth of his origins. A plucky youngster attended by her brutish guardian. A powerful artifact which has been broken into a small number of artifactlets distributed around the world.What do I want? Fewer damn cliches. - Sneftel

This topic is closed to new replies.

Advertisement