ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
#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;
}
}
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'
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)
{}
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.