Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,942 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,725 people online right now. Registration is fast and FREE... Join Now!




Error C4430 & C2143

 
Reply to this topicStart new topic

Error C4430 & C2143

skater_00
18 May, 2008 - 06:53 AM
Post #1

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
I've been trying to figure out for quite some time what is wrong with this piece of code, but I still didn't find a solution.

Below you see the temporary header file code to which the errors point:

cpp

// ----------------------- //
// >>>>> SONIC CLASS <<<<< //
// ----------------------- //

#pragma once

// >> Sonic - INCLUDE HEADERS AND/OR LIBRARIES <<
#include "GameEngine.h" // Include Game Engine v2.04 header.
#include "Attributes.h" // Include Attributes class header.
#include "Level.h"

class Sonic
{
public:
// >> Sonic - CONSTRUCTOR <<
Sonic(); // Prototype of the constructor used in Sonic.cpp.

// >> Sonic - DESTRUCTOR <<
virtual ~Sonic(); // Prototype of the destructor used in Sonic.cpp.

// >> Sonic - FUNCTIONS <<
// Prototypes of the functions used in Sonic.cpp.
void GameStart();
void GameEnd();
void CheckKeyboard();
void GameCycle(RECT rect);

private:
// >> Sonic - DECLARATION OF DATA MEMBERS <<

// Declarations of all data members of datatype "Bitmap".
Bitmap * m_BmpSonicRegularRightPtr, * m_BmpSonicRegularLeftPtr;

// Declarations of all data members of datatype "bool".
bool m_SonicRegularRight, m_SonicRegularLeft;

Attributes * m_AttributesPtr; // Class pointer used to refer to the class Attributes.
Level * m_LevelPtr;

Sonic(const Sonic& s);
Sonic& operator=(const Sonic& s);
};


This gives me 12 errors and all of them point to the same line (line 38 above):

cpp
Level * m_LevelPtr;


Errors:

QUOTE

Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 9 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 12 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 1 error C2143: syntax error : missing ';' before '*'
Error 4 error C2143: syntax error : missing ';' before '*'
Error 7 error C2143: syntax error : missing ';' before '*'
Error 10 error C2143: syntax error : missing ';' before '*'


I really don't understand why it is giving me these errors. I did the same thing with Attributes (Attributes * m_AttributesPtr;) and this works fine...

Any advice would be appreciated.
User is offlineProfile CardPM
+Quote Post

Cerolobo
RE: Error C4430 & C2143
18 May, 2008 - 08:09 AM
Post #2

D.I.C Regular
Group Icon

Joined: 5 Apr, 2008
Posts: 440



Thanked: 31 times
My Contributions
The compiler does not know what a "Level" is.

You did include "Level.h", which I assume has the Level class or structure. Did you make a spelling error, or capitalization error?
User is offlineProfile CardPM
+Quote Post

Voire
RE: Error C4430 & C2143
18 May, 2008 - 08:15 AM
Post #3

New D.I.C Head
*

Joined: 18 May, 2008
Posts: 1

Since you're only making use of a pointer to Level, you could get away with just giving a prototype for Level in that file. Above your class definition for 'Sonic', have:

CODE
class Level;

class Sonic
{
  ...

User is offlineProfile CardPM
+Quote Post

skater_00
RE: Error C4430 & C2143
18 May, 2008 - 12:19 PM
Post #4

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
QUOTE(Cerolobo @ 18 May, 2008 - 06:09 PM) *

The compiler does not know what a "Level" is.

You did include "Level.h", which I assume has the Level class or structure. Did you make a spelling error, or capitalization error?


Yes, "Level.h" contains the Level class. No spelling errors or capitalization errors made. Haven't since my 10th birthday.


QUOTE(Voire @ 18 May, 2008 - 06:15 PM) *

Since you're only making use of a pointer to Level, you could get away with just giving a prototype for Level in that file. Above your class definition for 'Sonic', have:

CODE
class Level;

class Sonic
{
  ...



I had already tried to add "class Level;" instead of "#include "Level.h"", but then it gives me the following 3 errors and 1 warning:

QUOTE

Warning 2 warning C4150: deletion of pointer to incomplete type 'Level'; no destructor called
Error 1 error C2512: 'Level' : no appropriate default constructor available
Error 4 error C2227: left of '->m_Y' must point to class/struct/union/generic type
Error 3 error C2027: use of undefined type 'Level'


None of the suggestions listed above make my Level class pointer work.

User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Error C4430 & C2143
18 May, 2008 - 12:27 PM
Post #5

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,514



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
What does your Level class look like?
User is offlineProfile CardPM
+Quote Post

skater_00
RE: Error C4430 & C2143
18 May, 2008 - 12:36 PM
Post #6

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
Header:

cpp

// ----------------------- //
// >>>>> LEVEL CLASS <<<<< //
// ----------------------- //

#pragma once

// >> Level - INCLUDE HEADERS AND/OR LIBRARIES <<
#include "GameEngine.h" // Include Game Engine v2.04 header.
#include "Outro.h" // Include Outro class header.
#include "Sonic.h" // Include Sonic class header.
#include "Attributes.h" // Include Attributes class header.

class Level : public Callable
{
friend class Sonic;
public:
// >> Level - CONSTRUCTOR <<
Level(); // Prototype of the constructor used in Level.cpp.

// >> Level - DESTRUCTOR <<
virtual ~Level(); // Prototype of the destructor used in Level.cpp.

// >> Level - FUNCTIONS <<
// Prototypes of the functions used in Level.cpp.
void GameStart();
void GameEnd();
void GameCycle(RECT rect);
void CallAction(Caller* c);

private:
// >> Level - DECLARATION OF DATA MEMBERS <<

Outro * m_OutroPtr; // Class pointer used to refer to the class Outro.
Sonic * m_SonicPtr; // Class pointer used to refer to the class Sonic.
Attributes * m_AttributesPtr; // Class pointer used to refer to the class Attributes.

// Declarations of all data members of datatype "Bitmap".
Bitmap * m_BmpTestPtr, * m_BmpTest2Ptr, * m_BmpScorePtr, * m_BmpRings1Ptr, * m_BmpRings2Ptr;

// Declarations of all data members of datatype "bool".
bool m_Zone1, m_Zone2, m_Rings1, m_Rings2;

// Declarations of all data members of datatype "Timer".
Timer * m_RingsTimerPtr;

int m_Y;

Level(const Level& s);
Level& operator=(const Level& s);
};


Cpp:

cpp

// ----------------------- //
// >>>>> LEVEL CLASS <<<<< //
// ----------------------- //

// >> Level - INCLUDE HEADERS AND/OR LIBRARIES <<
#include "Level.h" // Include Level class header.

// >> Level - DEFINES <<
#define GAME_ENGINE (GameEngine::GetSingleton()) // Retrieve access to Game Engine v2.04.

// >> Level - CONSTRUCTOR <<
Level::Level():m_OutroPtr(0), m_SonicPtr(0), m_AttributesPtr(0), m_BmpTestPtr(0), m_BmpTest2Ptr(0), m_BmpScorePtr(0), m_BmpRings1Ptr(0), m_BmpRings2Ptr(0), m_Zone1(true), m_Zone2(false),
m_Rings1(true), m_Rings2(false), m_RingsTimerPtr(0), m_Y(0) // Initializing data members.
{
m_OutroPtr = new Outro(); // Create a new instance of the class Outro with "new" and link it to m_OutroPtr. Use m_OutroPtr to refer to the class Outro.
m_SonicPtr = new Sonic(); // Create a new instance of the class Sonic with "new" and link it to m_SonicPtr. Use m_SonicPtr to refer to the class Sonic.
m_AttributesPtr = new Attributes(); // Create a new instance of the class Attributes with "new" and link it to m_AttributesPtr. Use m_AttributesPtr to refer to the class Attributes.
}

// >> Level - DESTRUCTOR <<
Level::~Level()
{
// Delete all the class pointers that were created with "new". One delete per line.
delete m_OutroPtr;
delete m_SonicPtr;
delete m_AttributesPtr;
}

// >> Level - FUNCTIONS <<
void Level::GameStart()
{
m_SonicPtr->GameStart();

m_BmpTestPtr = new Bitmap("Level\\Zone 1\\Test.bmp");
m_BmpTestPtr->SetTransparencyColor(RGB(0, 0, 0));
m_BmpTest2Ptr = new Bitmap("Level\\Zone 1\\Test2.bmp");
m_BmpScorePtr = new Bitmap("Bitmaps\\Score.bmp");
m_BmpScorePtr->SetTransparencyColor(RGB(255, 0, 255));
m_BmpRings1Ptr = new Bitmap("Bitmaps\\Rings-1.bmp");
m_BmpRings1Ptr->SetTransparencyColor(RGB(255, 0, 255));
m_BmpRings2Ptr = new Bitmap("Bitmaps\\Rings-2.bmp");
m_BmpRings2Ptr->SetTransparencyColor(RGB(255, 0, 255));
m_RingsTimerPtr = new Timer(100, this);
}

void Level::GameEnd()
{
delete m_BmpTestPtr;
delete m_BmpTest2Ptr;
delete m_BmpScorePtr;
delete m_BmpRings1Ptr;
delete m_BmpRings2Ptr;
delete m_RingsTimerPtr;
}

void Level::GameCycle(RECT rect)
{
GAME_ENGINE->SetKeyList(String() + (TCHAR) VK_UP + (TCHAR) VK_DOWN + (TCHAR) VK_LEFT + (TCHAR) VK_RIGHT + (TCHAR) VK_SPACE);

// ------------------------------ //
// Emerald Hill Zone 1 //
// ------------------------------ //
if (m_Zone1)
{
m_Y = GAME_ENGINE->GetHeight() / 2 - (m_BmpTestPtr->GetHeight() / 2) - 160;

GAME_ENGINE->DrawBitmap(m_BmpTest2Ptr, 0, 0);
GAME_ENGINE->DrawBitmap(m_BmpTestPtr, 0, m_Y);

GAME_ENGINE->DrawBitmap(m_BmpScorePtr, 10, 5);

if (m_Rings1) {
GAME_ENGINE->DrawBitmap(m_BmpRings1Ptr, 9, 21);

m_RingsTimerPtr->Start();
}

if (m_Rings2) {
GAME_ENGINE->DrawBitmap(m_BmpRings2Ptr, 9, 21);

m_RingsTimerPtr->Start();
}

m_SonicPtr->GameCycle(rect);
}

// ------------------------------ //
// Emerald Hill Zone 2 //
// ------------------------------ //
if (m_Zone2)
m_SonicPtr->GameCycle(rect);
}

void Level::CallAction(Caller* c)
{
if (c == m_RingsTimerPtr && m_Rings1) {
m_RingsTimerPtr->Stop();
m_Rings1 = false;
m_Rings2 = true;
} else if (c == m_RingsTimerPtr && m_Rings2) {
m_RingsTimerPtr->Stop();
m_Rings2 = false;
m_Rings1 = true;
}
}

User is offlineProfile CardPM
+Quote Post

Cerolobo
RE: Error C4430 & C2143
18 May, 2008 - 02:08 PM
Post #7

D.I.C Regular
Group Icon

Joined: 5 Apr, 2008
Posts: 440



Thanked: 31 times
My Contributions
You have a circular include.

When the compiler is compiling Level.h, Sonic.h is included. From Sonic.h, you reinclude Level.h. Since you have #pragma once, Level.h is not reincluded. At this point, you have just included GameEngine.h and Outra.h, but Sonic.h needs the the class Level (which is below the actual code).

So, this is basically what the compiler is working with.

cpp
// ----------------------- //
// >>>>> LEVEL CLASS <<<<< //
// ----------------------- //

// >> Level - INCLUDE HEADERS AND/OR LIBRARIES <<
#include "GameEngine.h" // Include Game Engine v2.04 header.
#include "Outro.h" // Include Outro class header.

// ----------------------- //
// >>>>> SONIC CLASS <<<<< //
// ----------------------- //

// >> Sonic - INCLUDE HEADERS AND/OR LIBRARIES <<
#include "GameEngine.h" // Include Game Engine v2.04 header.
#include "Attributes.h" // Include Attributes class header.
//#include "Level.h" // removed due to pragma once

class Sonic
{
public:
// >> Sonic - CONSTRUCTOR <<
Sonic(); // Prototype of the constructor used in Sonic.cpp.

// >> Sonic - DESTRUCTOR <<
virtual ~Sonic(); // Prototype of the destructor used in Sonic.cpp.

// >> Sonic - FUNCTIONS <<
// Prototypes of the functions used in Sonic.cpp.
void GameStart();
void GameEnd();
void CheckKeyboard();
void GameCycle(RECT rect);

private:
// >> Sonic - DECLARATION OF DATA MEMBERS <<

// Declarations of all data members of datatype "Bitmap".
Bitmap * m_BmpSonicRegularRightPtr, * m_BmpSonicRegularLeftPtr;

// Declarations of all data members of datatype "bool".
bool m_SonicRegularRight, m_SonicRegularLeft;

Attributes * m_AttributesPtr; // Class pointer used to refer to the class Attributes.
Level * m_LevelPtr;

Sonic(const Sonic& s);
Sonic& operator=(const Sonic& s);
};
// END OF SONIC.H

#include "Attributes.h" // Include Attributes class header.

class Level : public Callable
{
friend class Sonic;
public:
// >> Level - CONSTRUCTOR <<
Level(); // Prototype of the constructor used in Level.cpp.

// >> Level - DESTRUCTOR <<
virtual ~Level(); // Prototype of the destructor used in Level.cpp.

// >> Level - FUNCTIONS <<
// Prototypes of the functions used in Level.cpp.
void GameStart();
void GameEnd();
void GameCycle(RECT rect);
void CallAction(Caller* c);

private:
// >> Level - DECLARATION OF DATA MEMBERS <<

Outro * m_OutroPtr; // Class pointer used to refer to the class Outro.
Sonic * m_SonicPtr; // Class pointer used to refer to the class Sonic.
Attributes * m_AttributesPtr; // Class pointer used to refer to the class Attributes.

// Declarations of all data members of datatype "Bitmap".
Bitmap * m_BmpTestPtr, * m_BmpTest2Ptr, * m_BmpScorePtr, * m_BmpRings1Ptr, * m_BmpRings2Ptr;

// Declarations of all data members of datatype "bool".
bool m_Zone1, m_Zone2, m_Rings1, m_Rings2;

// Declarations of all data members of datatype "Timer".
Timer * m_RingsTimerPtr;

int m_Y;

Level(const Level& s);
Level& operator=(const Level& s);
};


The easiest way to fix this, is to use your original Sonic.h (the first post). In Level.h, remove

#include "Sonic.h" // Include Sonic class header.

and add

class Sonic;

You can do this, since you are only dealing with a pointer.

You should also remove

friend class Sonic;

since you don't access any of the private data.

in Level.cpp, you will have to add

#include "Sonic.h" // Include Sonic class header.
User is offlineProfile CardPM
+Quote Post

skater_00
RE: Error C4430 & C2143
18 May, 2008 - 02:25 PM
Post #8

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
That seems to work, thank you.

However, the "friend class Sonic;" is needed because I do access one of the private data members. Just checked it again, and when I remove it, I get an error saying one of the private members could not be accessed. So it needs to be there.

EDIT: It only compiles without errors. When I run it, it crashes with "Stack overflow" error.

This post has been edited by skater_00: 18 May, 2008 - 02:27 PM
User is offlineProfile CardPM
+Quote Post

Cerolobo
RE: Error C4430 & C2143
18 May, 2008 - 03:21 PM
Post #9

D.I.C Regular
Group Icon

Joined: 5 Apr, 2008
Posts: 440



Thanked: 31 times
My Contributions
I didn't see you access any private members... Anyway, apparently I was wrong on that part.

Stack Overflows are usually caused by infinite recursion loops. I doubt it's in the above code, so I can't really help you with that issue.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 08:41AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month