Sign in to follow this  
stenny

I thought constructors had no return types?!

Recommended Posts

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

Share this post


Link to post
Share on other sites
The error is probably somewhere before your constructor, such as a missing brace or semi-colon.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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_OVERLAPPEDWINDOW
const 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 5

class 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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Yes, I'm sure...I'm usingMicrosoft Visual Studio C++ EE with the same stats I always work with.

-Stenny

Share this post


Link to post
Share on other sites
Files with a .c extension are (or can be) still compiled as C code. But that's not the issue; the error message is one that occurs only when using C++.

There's likely a lot more wrong with your program than just not including the headers properly, and it only just surfaced because you started correctly including them. Post the first few errors and the source files they refer to.

Share this post


Link to post
Share on other sites
Ok, here are some:

Error 130 error C2059: syntax error : ')' g:\rpgdx\gamecores\inputcore\inputcore\core_input.cpp 29

Error 53 error C2061: syntax error : identifier 'BOOL' g:\rpgdx\gamecores\inputcore\inputcore\core_input.h 76

Error 4 error C2143: syntax error : missing ';' before '*' g:\rpgdx\gamecores\inputcore\inputcore\core_input.h 42

Error 119 error C2143: syntax error : missing ';' before 'cInput::GethWnd' g:\rpgdx\gamecores\inputcore\inputcore\core_input.cpp 19

Error 117 error C2227: left of '->Clear' must point to class/struct/union/generic type g:\rpgdx\gamecores\inputcore\inputcore\core_input.cpp 11

Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int g:\rpgdx\gamecores\inputcore\inputcore\core_input.h 41

Error 116 error C2065: 'm_pDI' : undeclared identifier g:\rpgdx\gamecores\inputcore\inputcore\core_input.cpp 11


-Stenny :)

---EDIT---
I know I might not have put a ; somewhere but I have no idea where...Also, I find it very strange the IDE doesn't recognize a BOOL. And yes, I use a Win32 Application project (Multi-Byte)

Share this post


Link to post
Share on other sites
Quote:
Original post by stenny
I included windows.h in Core_Global.h

-Stenny

But you didn't include it in Core_Input.cpp!
You should either include windows.h or Core_Global.h into your Core_Input.cpp file.

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