Identifier problem

Started by
2 comments, last by dalindeck 15 years, 3 months ago
I have absolutely no idea what's causing this problem, it pops up on every file that includes/uses the header, but as in this example they do include it. I commented the line that according to the compiler causes the error. This problem popped out of nowhere, aside from this identifier it tells me other two are missing aswell 'Application' and 'Direct3D. 1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\direct3d.h(35) : error C2061: syntax error : identifier 'Object'

#ifndef OBJECT_H
#define OBJECT_H

#include <d3d9.h>
#include <d3dx9.h>
#include "SpriteInstance.h"
#include "Application.h"
#include "Input.h"
#include <vector>


class Object
{
private:
	D3DXVECTOR2 position; 
	float rotation; 
	DWORD time_since_last_shot; 
	SpriteInstance sprite_instance;
	bool alive;

public:
	//constructors
	Object();
	Object(D3DXVECTOR2, float, DWORD, SpriteInstance, bool);
	virtual ~Object(){};

	//Action functions
	void move(float);
	void rotate(float);
	void check_collision(D3DXVECTOR2&);

	//Virtual functions
	virtual void update(Input&, Application&, std::vector<Object*>&) = 0;

	//Set functions
	void set_position(D3DXVECTOR2);
	void set_time_since_last_shot(DWORD);
	void set_sprite_instance(SpriteInstance);
	void set_state(bool);

	//Retrieve functions(?)
	D3DXVECTOR2 get_position() const;
	float get_rotation() const;
	DWORD get_time_since_last_shot() const;
	SpriteInstance get_sprite_instance() const;
	bool get_state() const;

	//Extra
	float degrees_to_radians(float);
};

#endif




#ifndef DIRECT_3D_H
#define DIRECT_3D_H

#include &lt;d3d9.h&gt;
#include &lt;d3dx9.h&gt;
#include "Coord.h"
#include "Object.h"
#include "Sprite.h"
#include "SpriteInstance.h"

#ifdef _DEBUG
# pragma comment(lib, "d3dx9d.lib")
#else
# pragma comment(lib, "d3dx9.lib")
#endif
# pragma comment(lib, "d3d9.lib")
	

class Direct3D
{
private:
	IDirect3D9* d3d_object;
	IDirect3DDevice9* d3d_device;
	LPD3DXSPRITE d3d_sprite;

public:
	//Direct3D routine
	bool init_d3d(HWND, Coord);
	void start_render();
	void end_render();	
	void close_directx();

	//Sprites
	Sprite* load_sprite(LPCTSTR);
//The below line of code is what causes the problem
	void draw_sprite(Object&);

	//Get Constants
	int get_size();
	RECT get_frame(SpriteInstance*, int);
	D3DXVECTOR2 get_scaling();
	D3DXVECTOR2 get_center();
};

#endif

Advertisement
Do you have similar include guards on your other headers?

Are these the only errors?

Have you tried compiling the source files one at a time?

----

What is an Object? Why does it not have any virtual functions besides the destructor and 'update'? What is 'update' supposed to do, and why does it accept a vector-of-pointers-to other Objects? How is check_collision going to work - does it only check if the Object overlaps the point in question?
Similar include guards, already checked and no :S..

An object is a game object, the class stores the object's position, the sprite instance it uses(Which in turn stores the object sprite's properties), the rotation, a boolean to test if its alive and so on. It also contains methods to move the object and rotate it.

The virtual method is because there are different types of objects. Here are two of the classes derived from object.

#ifndef SHIP_H#define SHIP_H#include <d3d9.h>#include <d3dx9.h>#include "Object.h"#include "SpriteInstance.h"#include "Application.h"#include "Object.h"#include "Input.h"#include <vector>class Ship: public Object{public:	Ship();	Ship(D3DXVECTOR2, float, DWORD, SpriteInstance, bool);	void update(Input&, Application&, std::vector<Object*>&);};#endif


#include <d3d9.h>#include <d3dx9.h>#include "Ship.h"#include "Application.h"#include "SpriteInstance.h"#include "Missile.h"#include "Object.h"#include "Input.h"#include <vector>float get_theta(){	return 3.0f;}float get_displacement(){	return 3.0f;}DWORD get_cooldown(){	return 170;}bool check_state(Object &object){	return object.get_state();}Ship::Ship():Object(){}Ship::Ship(D3DXVECTOR2 new_position, 		   float new_rotation, 		   DWORD new_time_since_last_shot,		   SpriteInstance new_sprite_instance,		   bool new_state): Object(new_position, 	   new_rotation, 	   new_time_since_last_shot,	   new_sprite_instance,	   new_state){}void Ship::update(Input &input, 				  Application &application, 				  std::vector<Object*> &game_objects){	//Move	if(input.move_forward)	{		move(get_displacement());		}    	if(input.move_backward)	{		(-get_displacement());	}	//Rotate	if(input.turn_right)	{		rotate(get_theta());	}	if(input.turn_left)	{		rotate(-get_theta());	}		//Attack	DWORD time = timeGetTime();	if(input.shooting == true)	{		if((time - get_time_since_last_shot()) > get_cooldown())		{			set_time_since_last_shot(time);			Object *object_pointer = new Missile(get_position(), 												 get_rotation(), 												 0, 												 (application.get_sprite("missile")), 												 true);			object_pointer->move(5);			game_objects.push_back(object_pointer);		}	}	std::vector<Object*>::iterator it;	it = game_objects.begin();	for(; it != game_objects.end(); it++)	{		check_collision((*it)->get_position());	}}


#ifndef MISSILE_H#define MISSILE_H#include <d3d9.h>#include <d3dx9.h>#include "Object.h"#include "Input.h"#include "Application.h"#include "SpriteInstance.h"#include <vector>class Missile: public Object{public:	Missile();	Missile(D3DXVECTOR2, float, DWORD, SpriteInstance, bool);	void update(Input&, Application&, std::vector<Object*>&);};#endif


#include <d3d9.h>#include <d3dx9.h>#include "Missile.h"#include "Object.h"#include <vector>Missile::Missile():Object(){}Missile::Missile(D3DXVECTOR2 new_position, 			     float new_rotation, 			     DWORD new_time_since_last_shot,				 SpriteInstance new_sprite_instance,				 bool new_state): Object(new_position, 	   new_rotation, 	   new_time_since_last_shot,	   new_sprite_instance,	   new_state){}void Missile::update(Input &input, 				  Application &application, 				  std::vector<Object*> &game_objects){	move(5);}


Here's the collision function

//Check collisionvoid Object::check_collision(D3DXVECTOR2 &position2){	if((&position != &position2 &&		position.x < (position2.x + 32) &&	    position.x > (position2.x - 32) &&		position.y < (position2.y + 32) &&		position.y > (position2.y - 32)))	{		set_state(false);	}}



This is the entire list of errors.
>Compiling...
1>Direct3D.cpp
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\application.h(25) : error C2061: syntax error : identifier 'Direct3D'
1>Render.cpp
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\object.h(33) : error C2061: syntax error : identifier 'Application'
1>Application.cpp
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\object.h(33) : error C2061: syntax error : identifier 'Application'
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\application.cpp(96) : warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG', possible loss of data
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\application.cpp(100) : warning C4312: 'reinterpret_cast' : conversion from 'LONG' to 'Application *' of greater size
1>Asteroid.cpp
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\direct3d.h(35) : error C2061: syntax error : identifier 'Object'
1>Logic.cpp
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\object.h(33) : error C2061: syntax error : identifier 'Application'
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\logic.cpp(16) : error C2259: 'Ship' : cannot instantiate abstract class
1> due to following members:
1> 'void Object::update(Input &)' : is abstract
1> c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\object.h(33) : see declaration of 'Object::update'
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\logic.cpp(20) : error C2259: 'Asteroid' : cannot instantiate abstract class
1> due to following members:
1> 'void Object::update(Input &)' : is abstract
1> c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\object.h(33) : see declaration of 'Object::update'
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\logic.cpp(35) : error C2660: 'Object::update' : function does not take 3 arguments
1>Loop.cpp
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\object.h(33) : error C2061: syntax error : identifier 'Application'
1>Missile.cpp
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\direct3d.h(35) : error C2061: syntax error : identifier 'Object'
1>Object.cpp
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\direct3d.h(35) : error C2061: syntax error : identifier 'Object'
1>Ship.cpp
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\direct3d.h(35) : error C2061: syntax error : identifier 'Object'
1>WinMain.cpp
1>c:\documents and settings\david\mis documentos\visual studio 2005\projects\dungeon\dungeon\object.h(33) : error C2061: syntax error : identifier 'Application'
1>Generating Code...
1>Build log was saved at "file://c:\Documents and Settings\David\Mis documentos\Visual Studio 2005\Projects\Dungeon\Dungeon\Debug\BuildLog.htm"
1>Dungeon - 13 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
One thing that I've noticed (no idea if I have the right answer here), is that you seem to include the <d3d9.h> and <d3dx9.h> files NUMEROUS times in a ton of different files. If you are including them in one header file, then including that header file into another one, you don't have to re-include those files ;)

For example:

blah.h
#ifndef BLAH_H#define BLAH_H#include <d3d9.h>#include <d3dx9.h>#endif //BLAH_H


blah.cpp
#include "blah.h"#include <d3d9.h> //Not needed#include <d3dx9.h> //Not needed


Or at least I don't think they are XD.
Jacob Foster
Software Engineering student at the Oregon Institute of Technology

This topic is closed to new replies.

Advertisement