Sign in to follow this  

Sanity check - Identifier issue

This topic is 3464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I must be going crazy... I can't figure out why I'm getting these errors...
#ifndef RUDEY_ENEMY_H
#define RUDEY_ENEMY_H

#include "SDL/SDL.h"

#include "Cloneable.h"
#include "Direction.h"
#include "Drawable.h"
#include "SDL_Tools.h"
#include "Updateable.h"
#include "XImage.h"

#include "Rudey_Clock.h"
#include "Rudey_Level.h"

class Rudey_Enemy : public XImage
{
public:
	Rudey_Enemy();
	Rudey_Enemy(
		int speed,
		const std::string& name,
		const std::string& file_name,
		Point xy,
		bool is_colour_key,
		SDL_Colour colour_key = SDL_Tools::colour(255,255,255));
	virtual ~Rudey_Enemy();

	int Get_Speed() const;

	void Move(Direction::DIRECTION dir);
public:
	virtual void Draw();
	virtual void Update(const SDL_Event& event_);
	//virtual Rudey_Enemy* Clone() const;
private:
	int speed;
};

#endif
#include "Rudey_Enemy.h"

Rudey_Enemy::Rudey_Enemy()
	:
	speed(0)
{
}

Rudey_Enemy::Rudey_Enemy(
	int speed,
	const std::string& name,
	const std::string& file_name,
	Point xy,
	bool is_colour_key,
	SDL_Colour colour_key)
	:
	XImage(name, file_name, xy.x, xy.y, is_colour_key, colour_key),
	speed(speed)
{
	position.w = SDL_Tools::get_surface_size(surface).x;
	position.h = SDL_Tools::get_surface_size(surface).y;
}

Rudey_Enemy::~Rudey_Enemy()
{
}

int Rudey_Enemy::Get_Speed() const
{
	return speed;
}

void Rudey_Enemy::Move(Direction::DIRECTION dir)
{
	position = SDL_Tools::move_by(position, dir, Rudey_Level::TILE_WIDTH);
}

void Rudey_Enemy::Draw()
{
	Draw_Engine::Blit_Surface(position, surface, NULL);
}

void Rudey_Enemy::Update(const SDL_Event& event_)
{
	//if(Rudey_Clock::Get_Ticks() >= speed)
	//{
	//	// move some random position
	//}
}

//Rudey_Enemy*; Rudey_Enemy::Clone() const
//{
//	return new Rudey_Enemy(*this);
//}
#ifndef RUDEY_LEVEL_H
#define RUDEY_LEVEL_H

#include <vector>
#include <string>

#include "Rudey.h"
#include "Rudey_Clock.h"
#include "Rudey_Enemy.h"

class Rudey_Level
{
public:
	Rudey_Level();
	Rudey_Level(Rudey* rudey, int difficulty);
	~Rudey_Level();

	static int TILE_WIDTH, TILE_HEIGHT;
private:
	Rudey* rudey;
	int difficulty;
	std::vector<Rudey_Enemy> enemies;
};

#endif

#include "Rudey_Level.h"

int Rudey_Level::TILE_WIDTH = 25;
int Rudey_Level::TILE_HEIGHT = 25;

Rudey_Level::Rudey_Level()
	:
	rudey(NULL),
	difficulty(0)
{
}

Rudey_Level::Rudey_Level(Rudey* rudey, int difficulty)
	:
	rudey(rudey),
	difficulty(difficulty)
{
}

Rudey_Level::~Rudey_Level()
{
}

Quote:
error C2146: syntax error : missing ';' before identifier 'r' 23 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 23 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 23
Cheers.

Share this post


Link to post
Share on other sites
Which line of which file is the error on? (i.e. post the rest of the error message). You should be able to double-click the error message to go to that line.

Share this post


Link to post
Share on other sites
#ifndef RUDEY_ENEMY_H
#define RUDEY_ENEMY_H

#include "SDL/SDL.h"

#include "Cloneable.h"
#include "Direction.h"
#include "Drawable.h"
#include "SDL_Tools.h"
#include "Updateable.h"
#include "XImage.h"

#include "Rudey_Clock.h"
#include "Rudey_Level.h"

class Rudey_Enemy : public XImage
{
public:
Rudey_Enemy();
Rudey_Enemy(
int speed,
const std::string& name,
const std::string& file_name,
Point xy,
bool is_colour_key,
SDL_Colour colour_key = SDL_Tools::colour(255,255,255));
virtual ~Rudey_Enemy();

int Get_Speed() const;

void Move(Direction::DIRECTION dir);
public:
virtual void Draw();
virtual void Update(const SDL_Event& event_);
//virtual Rudey_Enemy* Clone() const;
private:
int speed;
};

#endif

You have a circular inclusion error - RudeyEnemy.h includes RudeyLevel.h and RudeyLevel.h includes RudeyEnemy.h. The former include is unneccessary.

Σnigma

Share this post


Link to post
Share on other sites
Quote:
Original post by Mybowlcut
Oh... but I need Rudey_Level::TILE_WIDTH in Rudey_Enemy.cpp...


Then include it in the .cpp and not in the .h. In C++, you should move your inclusions in the source files (.cpp) whenever possible to avoid such problems.

Share this post


Link to post
Share on other sites
See, this is what I never got... what is the difference between moving it to the .cpp file? I thought the .h and .cpp got merged together during compilation into a .obj file?

Share this post


Link to post
Share on other sites
The difference is that every other file that #include your header will include automatically every header you #include there. If you #include an header in your c++ file you will not espose that header to others.

The general rule is: never include an header file in you header files. Include only those file that you are forced to use.

Example: you use a std::string object in you header -> you must #include "string"

Example: you use a reference to a c++ stream in your header -> you must not include iostream, fstream or others. Perhaps #include "iosfwd" will suffice. That particular header contains only typedefs of c++ standard headers and then is parsed very quickly.

An other important rule is: never assume that a module that can be build together with other modules can be compiled alone. Your header file "Rudey_Enemy.h" uses a std::string& but do not include the corresponding header. It compile probably because it's used in other headers the #include "string". You must include every headers in order to have modules that can be compiled alone in a graceful way.

Share this post


Link to post
Share on other sites
Quote:
Original post by zaerl
The difference is that every other file that #include your header will include automatically every header you #include there. If you #include an header in your c++ file you will not espose that header to others.

The general rule is: never include an header file in you header files. Include only those file that you are forced to use.

Example: you use a std::string object in you header -> you must #include "string"

Example: you use a reference to a c++ stream in your header -> you must not include iostream, fstream or others. Perhaps #include "iosfwd" will suffice. That particular header contains only typedefs of c++ standard headers and then is parsed very quickly.

An other important rule is: never assume that a module that can be build together with other modules can be compiled alone. Your header file "Rudey_Enemy.h" uses a std::string& but do not include the corresponding header. It compile probably because it's used in other headers the #include "string". You must include every headers in order to have modules that can be compiled alone in a graceful way.
I read the article but I didn't see anything mentioned about the rule that zaerl mentioned.

I moved the "Rudey_Level" include to the "Rudey_Enemy.cpp" file and it worked. Cheers for that! :D

Share this post


Link to post
Share on other sites

This topic is 3464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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