8 Replies - 7211 Views - Last Post: 18 May 2008 - 04:21 PM Rate Topic: -----

#1 skater_00  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • Posts: 256
  • Joined: 30-April 08

Error C4430 & C2143

Post icon  Posted 18 May 2008 - 07:53 AM

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:

// ----------------------- //
// >>>>> 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):

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.

Is This A Good Question/Topic? 0
  • +

Replies To: Error C4430 & C2143

#2 Cerolobo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 52
  • View blog
  • Posts: 450
  • Joined: 05-April 08

Re: Error C4430 & C2143

Posted 18 May 2008 - 09:09 AM

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?
Was This Post Helpful? 0
  • +
  • -

#3 Voire  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-May 08

Re: Error C4430 & C2143

Posted 18 May 2008 - 09:15 AM

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:

class Level;

class Sonic
{
  ...


Was This Post Helpful? 0
  • +
  • -

#4 skater_00  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • Posts: 256
  • Joined: 30-April 08

Re: Error C4430 & C2143

Posted 18 May 2008 - 01:19 PM

View PostCerolobo, on 18 May, 2008 - 06:09 PM, said:

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.


View PostVoire, on 18 May, 2008 - 06:15 PM, said:

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:

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.
Was This Post Helpful? 0
  • +
  • -

#5 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Error C4430 & C2143

Posted 18 May 2008 - 01:27 PM

What does your Level class look like?
Was This Post Helpful? 0
  • +
  • -

#6 skater_00  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • Posts: 256
  • Joined: 30-April 08

Re: Error C4430 & C2143

Posted 18 May 2008 - 01:36 PM

Header:

// ----------------------- //
// >>>>> 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:

// ----------------------- //
// >>>>> 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;
	}
}


Was This Post Helpful? 0
  • +
  • -

#7 Cerolobo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 52
  • View blog
  • Posts: 450
  • Joined: 05-April 08

Re: Error C4430 & C2143

Posted 18 May 2008 - 03:08 PM

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.

// ----------------------- //
// >>>>> 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.
Was This Post Helpful? 1

#8 skater_00  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • Posts: 256
  • Joined: 30-April 08

Re: Error C4430 & C2143

Posted 18 May 2008 - 03:25 PM

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 - 03:27 PM

Was This Post Helpful? 0
  • +
  • -

#9 Cerolobo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 52
  • View blog
  • Posts: 450
  • Joined: 05-April 08

Re: Error C4430 & C2143

Posted 18 May 2008 - 04:21 PM

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1