LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-05-2005, 08:26 PM   #1
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Rep: Reputation: 47
c++ not qualified to give good subject line.


It has been over a year since I used c++ last time.. and I never got even as complicated as this little thing then.

I have been trying awhile... but I am at my whits end, the most I can do is post the code (4 headers and 4 files corresponding) and the error, if anyone could please even just give me a hint or a link to a doc that explains it that would be helpful, I do not even know where to begin searching for the solution to this other than here.

my background:

I am very familiar w/ java, perl, and shell scripting.
I am basically rewriting a java program of mine, bu tin c++ (I am not looking back to my java code for any actual code, only for ideas, I am not simply copying and pasting then trying to modify the java ciode into c++ code, I knwo that is harder than it is worth.

this is all the code I have so far (started today) I am just trying to get these files to compile (they are not finished yet) now so that I know I have a sturdy base... apparently I don't though.

here is my compiler command line:

g++ -c MapObject.cc

the error first of all:
Code:
In file included from ActiveMap.h:4,
                 from MapObject.h:3,
                 from MapObject.cc:1:
StaticMap.h:13: error: `MapObject' has not been declared
StaticMap.h:13: error: ISO C++ forbids declaration of `parameter' with no type
StaticMap.h:15: error: `MapObject' has not been declared
StaticMap.h:15: error: ISO C++ forbids declaration of `parameter' with no type
StaticMap.h:17: error: ISO C++ forbids declaration of `list' with no type
StaticMap.h:17: error: expected `;' before '<' token
StaticMap.h:22: error: ISO C++ forbids declaration of `list' with no type
StaticMap.h:22: error: expected `;' before '<' token
In file included from MapObject.h:3,
                 from MapObject.cc:1:
ActiveMap.h:16: error: `MapObject' has not been declared
ActiveMap.h:16: error: ISO C++ forbids declaration of `parameter' with no type
ActiveMap.h:18: error: `MapObject' has not been declared
ActiveMap.h:18: error: ISO C++ forbids declaration of `parameter' with no type
ActiveMap.h:20: error: `MapObject' has not been declared
ActiveMap.h:20: error: ISO C++ forbids declaration of `parameter' with no type
ActiveMap.h:22: error: ISO C++ forbids declaration of `MapObject' with no type
ActiveMap.h:22: error: expected `;' before '&' token
ActiveMap.h:24: error: `MapObject' has not been declared
ActiveMap.h:24: error: ISO C++ forbids declaration of `parameter' with no type
ActiveMap.h:34: error: ISO C++ forbids declaration of `list' with no type
ActiveMap.h:34: error: expected `;' before '<' token
In file included from MapObject.h:4,
                 from MapObject.cc:1:
Chaser.h:11: error: `MapObject' has not been declared
Chaser.h:11: error: ISO C++ forbids declaration of `parameter' with no type
In file included from MapObject.cc:1:
MapObject.h:46: error: ISO C++ forbids declaration of `list' with no type
MapObject.h:46: error: expected `;' before '<' token
MapObject.cc: In member function `void OpenRPGGDE::MapObject::addChaser(OpenRPGGDE::Chaser&)':
MapObject.cc:75: error: `Chasers' undeclared (first use this function)
MapObject.cc:75: error: (Each undeclared identifier is reported only once for each function it appears in.)
MapObject.cc: In member function `void OpenRPGGDE::MapObject::removeChaser(OpenRPGGDE::Chaser&)':
MapObject.cc:80: error: `Chasers' undeclared (first use this function)
MapObject.cc: In member function `void OpenRPGGDE::MapObject::checkZone(int, int)':
MapObject.cc:93: error: no matching function for call to `OpenRPGGDE::ActiveMap::changeZone(OpenRPGGDE::MapObject* const, int&, int&)'
ActiveMap.h:24: note: candidates are: void OpenRPGGDE::ActiveMap::changeZone(int&, int, int)

MapObject.h:

Code:
#ifndef MAPOBJECT_H
#define MAPOBJECT_H
#include "ActiveMap.h"
#include "Chaser.h"
#include "StaticMap.h"
using namespace std;

namespace OpenRPGGDE
{
	class MapObject
	{
	public:
		MapObject();
		
		MapObject(int, int, ActiveMap&);
		
		int getX();
		
		int getY();
		
		void setX(int);
		
		void setY(int);
		
		void changeX(int);
		
		void changeY(int);
		
		void setCoord(int, int);
		
		void changeCoord(int, int);
		
		void addChaser(Chaser&);
		
		void removeChaser(Chaser&);
	
		virtual bool isDynamic();
		
		void checkZone(int, int); //Previous X and Y
		
		void setMap(ActiveMap&); //This is the map the object is now on, map is already notified of this objects appearence, map should not be told to add this object.
	
	protected:
		int xCoord;
		int yCoord;
		list<*Chaser> Chasers;
		ActiveMap *currentMap;
	};
}
#endif //MAPOBJECT_H
MapObject.cc:
Code:
#include "MapObject.h"
#include "ActiveMap.h"
#include "Chaser.h"
using namespace std;

namespace OpenRPGGDE
{
	MapObject::MapObject() : xCoord(0), yCoord(0) {}
	
	MapObject::MapObject(int X, int Y, ActiveMap& theMap)
	{
		xCoord = X;
		yCoord = Y;
		currentMap = &theMap;
	}
	
	int MapObject::getX()
	{
		return xCoord;
	}
	
	int MapObject::getY()
	{
		return yCoord;
	}
	
	void MapObject::setX(int X)
	{
		int oldX = xCoord;
		xCoord = X;
		checkZone(oldX, yCoord);
	}
	
	void MapObject::setY(int Y)
	{
		int oldY = yCoord;
		yCoord = Y;
		checkZone(xCoord, oldY);
	}
	
	void MapObject::changeX(int X)
	{
		int oldX = xCoord;
		xCoord += X;
		checkZone(oldX, yCoord);
	}
	
	void MapObject::changeY(int Y)
	{
		int oldY = yCoord;
		yCoord += Y;
		checkZone(xCoord, oldY);
	}
	
	void MapObject::setCoord(int X, int Y)
	{
		int oldX = xCoord;
		int oldY = yCoord;
		xCoord = X;
		yCoord = Y;
		checkZone(oldX, oldY);
	}

	void MapObject::changeCoord(int X, int Y)
	{
		int oldX = xCoord;
		int oldY = yCoord;
		xCoord += X;
		yCoord += Y;
		checkZone(oldX, oldY);
	}

	void MapObject::addChaser(Chaser& theChaser)
	{
		Chasers.push_front(&theChaser);
	}
	
	void MapObject::removeChaser(Chaser& theChaser)
	{
		Chasers.remove(&theChaser);
	}
	
	bool MapObject::isDynamic()
	{
		return false;
	}
	
	void MapObject::checkZone(int X, int Y)
	{
		int zs = currentMap->getZoneSize();
		if ((X/zs != xCoord/zs) || (Y/zs != yCoord/zs))
		{
			currentMap->changeZone(this, X, Y);
		}
	}
	
	void MapObject::setMap(ActiveMap& theMap)
	{
		currentMap = &theMap;
	}
}
Chaser.h:
Code:
#ifndef CHASER_H
#define CHASER_H
#include "MapObject.h"
using namespace std;

namespace OpenRPGGDE
{
	class Chaser
	{
	public:
		virtual void endChase(MapObject&);
	};
}
#endif //CHASER_H
Chaser.cc:
Code:
#include "Chaser.h"
#include "MapObject.h"
using namespace std;
using namespace OpenRPGGDE;

namespace OpenRPGGDE
{
	void Chaser::endChase(MapObject& theObject)
	{}
}
StaticMap.h:
Code:
#ifndef STATICMAP_H
#define STATICMAP_H
#include "MapObject.h"
using namespace std;

namespace OpenRPGGDE
{
	class StaticMap
	{
	public:
		StaticMap(int);
		
		void addObject(MapObject&);
		
		void removeObject(MapObject&);
		
		list<*MapObject> getObjects();
		
		int getMapSize();
	
	private:
		list<*MapObject> theObjects;
		
		int mapSize;
	};
}
#endif //STATICMAP_H
StaticMap.cc:
Code:
#include "StaticMap.h"
#include "MapObject.h"
using namespace std;
using namespace OpenRPGGDE;

namespace OpenRPGGDE
{
	StaticMap::StaticMap(int ms)
	{
		mapSize = ms;
	}
	
	void StaticMap::addObject(MapObject& theObject)
	{
		theObjects.push_front(&theObject);
	}
	
	void StaticMap::removeObject(MapObject& theObject)
	{
		theObjects.remove(&theObject);
	}
	
	list<*MapObject> StaticMap::getObjects()
	{
		list<*MapObject> out;
		list<*MapObject>::iterator I;
		for(I = theObjects.begin(); I != theObjects.end(); I++)
		{
			out.push_front(theIterator);
		}
	}
	
	int StaticMap::getMapSize()
	{
		return mapSize;
	}
}
ActiveMap.h:
Code:
#ifndef ACTIVEMAP_H
#define ACTIVEMAP_H
#include "MapObject.h"
#include "StaticMap.h"
using namespace std;

namespace OpenRPGGDE
{
	class ActiveMap
	{
	public:
		ActiveMap(StaticMap, int); //The static Map to build from, and an int for Zone size.
		
		~ActiveMap();
		
		void addObject(MapObject&, int, int);
		
		void addObjectRandom(MapObject&);
		
		void removeObject(MapObject&);
		
		MapObject& grab(int, int, int); // X coordinate, Y coordinate, radius
		
		void changeZone(MapObject&,int, int); //Object that changed zones, old x and y coordinates (old zone)
		
		int getZoneSize();
		
		int getMapSize();
	
	private:
		int zoneSize;
		int mapSize;
		int zones;
		list<*MapObject> *zoneArray;
	};
}
#endif //ACTIVEMAP_H
ActiveMap.cc:
Code:
#include "ActiveMap.h"
#include "MapObject.h"
#include "StaticMap.h"
using namespace std;
using namespace OpenRPGGDE;

namespace OpenRPGGDE
{
	ActiveMap::ActiveMap(StaticMap theMap, int zSize)
	{
		mapSize = theMap.getMapSize();
		//the size of a zone cannot be larger than the map itself.
		zoneSize = zSize;
		if (zoneSize > mapSize)
		{
			zoneSize  = MapSize;
		}
		//Mapsize needs to be divided into zones, so it must divide evenly, if it does not increase zonesize till it does, if all else fails there will be 1 zone, cannot count down because a number too low becomes to cpu intensive, on the flip side though a number too high can also increase cpu work from list iterations.
		while (mapSize%zoneSize != 0)
		{
			zoneSize++;
		}
		
		zones = mapSize/zoneSize; //zones is total zone grids on each plane, if zones is 5 then the grid is 5x5
		
		zoneArray = new *list<*MapObject>[zones];
		for (int I = 0; I < zones; I++) //first dimension is X axis, we need [zones] of them
		{
			zoneArray[I] = new *list<*MapObject>[zones]; //second dimension is Y axis, we need [zones] of these as well
			for (int J = 0; J < zones; J++)
			{
				zoneArray[I][J] = new list<*MapObject>[2]; //third dimension, 0 is statix, unmoving objects (rocks, trees), 1 is characters, items, and moving things, dynamic objects.
			}
		}
	}
	
	ActiveMap:~ActiveMap()
	{
		for (int I = 0; I < zones; I++)
		{
			for (int J = 0; J < zones; J++)
			{
				delete[] zoneArray[I][J];
			}
			delete[] zoneArray[I];
		}
		delete[] zoneArray
	}
	
	void ActiveMap::addObject(MapObject& theObject, int X, int Y)
	{
	}
	
	void ActiveMap::addObjectRandom(MapObject& theObject)
	{
	
	}
	
	void ActiveMap::removeObject(MapObject& theObject)
	{
	
	}
	
	MapObject& ActiveMap::grab(int X, int Y, int R)
	{
	
	}
	
	void ActiveMap::changeZone(MapObject& theObject, int oldX, int oldY)
	{
	}
	
	int ActiveMap::getZoneSize()
	{
		return zoneSize;
	}
	
	int ActiveMap::getMapSize()
	{
		return mapSize;
	}
}
 
Old 06-05-2005, 08:38 PM   #2
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Original Poster
Rep: Reputation: 47
ok, I added #include <list> to the top of all the headers but Chaser.h (didn't need it) now the error is different:
Code:
In file included from ActiveMap.h:4,
                 from MapObject.h:3,
                 from MapObject.cc:1:
StaticMap.h:15: error: `MapObject' has not been declared
StaticMap.h:15: error: ISO C++ forbids declaration of `parameter' with no type
StaticMap.h:17: error: `MapObject' has not been declared
StaticMap.h:17: error: ISO C++ forbids declaration of `parameter' with no type
StaticMap.h:19: error: `MapObject' was not declared in this scope
StaticMap.h:19: error: `*' cannot appear in a constant-expression
StaticMap.h:19: error: template argument 1 is invalid
StaticMap.h:19: error: template argument 2 is invalid
StaticMap.h:19: error: ISO C++ forbids declaration of `getObjects' with no type
StaticMap.h:24: error: `MapObject' was not declared in this scope
StaticMap.h:24: error: `*' cannot appear in a constant-expression
StaticMap.h:24: error: template argument 1 is invalid
StaticMap.h:24: error: template argument 2 is invalid
StaticMap.h:24: error: ISO C++ forbids declaration of `theObjects' with no type
In file included from MapObject.h:3,
                 from MapObject.cc:1:
ActiveMap.h:18: error: `MapObject' has not been declared
ActiveMap.h:18: error: ISO C++ forbids declaration of `parameter' with no type
ActiveMap.h:20: error: `MapObject' has not been declared
ActiveMap.h:20: error: ISO C++ forbids declaration of `parameter' with no type
ActiveMap.h:22: error: `MapObject' has not been declared
ActiveMap.h:22: error: ISO C++ forbids declaration of `parameter' with no type
ActiveMap.h:24: error: ISO C++ forbids declaration of `MapObject' with no type
ActiveMap.h:24: error: expected `;' before '&' token
ActiveMap.h:26: error: `MapObject' has not been declared
ActiveMap.h:26: error: ISO C++ forbids declaration of `parameter' with no type
ActiveMap.h:36: error: `MapObject' was not declared in this scope
ActiveMap.h:36: error: `*' cannot appear in a constant-expression
ActiveMap.h:36: error: template argument 1 is invalid
ActiveMap.h:36: error: template argument 2 is invalid
ActiveMap.h:36: error: ISO C++ forbids declaration of `zoneArray' with no type
In file included from MapObject.h:4,
                 from MapObject.cc:1:
Chaser.h:11: error: `MapObject' has not been declared
Chaser.h:11: error: ISO C++ forbids declaration of `parameter' with no type
In file included from MapObject.cc:1:
MapObject.h:47: error: `*' cannot appear in a constant-expression
MapObject.h:47: error: template argument 1 is invalid
MapObject.h:47: error: template argument 2 is invalid
MapObject.h:47: error: ISO C++ forbids declaration of `Chasers' with no type
MapObject.cc: In member function `void OpenRPGGDE::MapObject::addChaser(OpenRPGGDE::Chaser&)':
MapObject.cc:75: error: request for member `push_front' in `((OpenRPGGDE::MapObject*)this)->OpenRPGGDE::MapObject::Chasers', which is of non-class type `int'
MapObject.cc: In member function `void OpenRPGGDE::MapObject::removeChaser(OpenRPGGDE::Chaser&)':
MapObject.cc:80: error: request for member `remove' in `((OpenRPGGDE::MapObject*)this)->OpenRPGGDE::MapObject::Chasers', which is of non-class type `int'
 
Old 06-06-2005, 05:53 AM   #3
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
I saw several dubious things in the code, and here's one thing:
if you have a std::list that you want to contain pointer to objects of type foo,
you do std::list<foo*> mylist;

In mapobject.h, for example, you have list<*Chaser>, change that to list<Chaser*>.
Do that for all std::list-objects where it applies. Also, it's considered poor style to have
using namespace std; statement in a header because that forces everyone who includes
such a header to bring everything into the global namespace which pretty much defeats
the purpose of namespaces.
The constructor for MapObject isn't very good because you have nasty aliasing issue.
Code:
MapObject::MapObject(int X, int Y, ActiveMap& theMap)
{
   xCoord = X;
   yCoord = Y;
   currentMap = &theMap;
}
Rewrite that as (and make it inline) and change the type of currentMap so it isn't a pointer:
Code:
MapObject::MapObject(int X, int Y, const ActiveMap& theMap)
   :
   xCoord(X),
   yCoord(Y),
   currentMap(theMap)
{}

Last edited by Hivemind; 06-06-2005 at 05:54 AM.
 
Old 06-06-2005, 08:41 AM   #4
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Original Poster
Rep: Reputation: 47
thank you
 
Old 06-06-2005, 10:51 AM   #5
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Original Poster
Rep: Reputation: 47
CurrentMap needs to be a pointer.. I think.. basically it is a map that contains all the mapobjects and they all need to be interactive, so the currentmap referenced by the mapobject needs to be the same currentmap the other objects reference, not a copy of it, that way when there is a chage it does not need to be done seperately for each one.
 
Old 06-07-2005, 02:59 AM   #6
jwn7
Member
 
Registered: Aug 2004
Location: pittsburgh, pa
Distribution: gentoo
Posts: 81

Rep: Reputation: 15
i think you need to write a makefile and use make to build your project instead of compiling just one file
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Piping to mail and adding a subject line. Echo Kilo Linux - General 1 12-03-2005 11:24 AM
SpamAssassin won't rewrite Subject line mindfrost82 Linux - Software 2 09-18-2005 10:16 AM
How to change the subject line of Thread with "Solved" ? anindyanuri LQ Suggestions & Feedback 6 05-09-2005 12:57 PM
Spamassasin, Tagging Subject line lapthorn Linux - Networking 1 09-30-2004 04:19 PM
suggestions for subject line when posting. abrakadabra LQ Suggestions & Feedback 14 05-16-2002 09:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration