0

Hello,

I'm having this problem in my code that I just can't figure out the reason to, I'm trying to set an integer value to an integer variable that's a member of a class that is part of an array member of another class.
It should be an int = int, same type of variable, and should work.
However, it produces this error, which I think means that the value on the left of the '=' is not recognized of the correct type, though, I can't be sure, as MSDN is really foggy about this, and I haven't quite found anything similiar happening to anyone on a Google search for it.

This is the way it's built:

Project.h:

template <class T>
inline std::string to_string (const T& t);

class Project{
public: 
	friend class Map;

	list<Map> maps;
	list<Map>::iterator it;

	Project();
};

public ref class MProject{
public:
	Project * _p;
	MProject();
};

Map.h:

class Map{
public:
	friend class Tile;

	//An array of the tiles the map consists.
	Tile *tile;

	//Provides easy access to the matrix format of the map.
	//x and y are to be entered by tiles and not by pixels.
	Tile getTile(int x, int y);

	Map::Map(int width, int height);
	Map::Map(list<Map>::iterator it);
};

public ref class MMap{
public:
	Map * _m;
	MMap(int width, int height);
}

The following are the functions that seem to be the main attraction for errors, however, in actuality, they haven't seemed to produce any yet.
Map.cpp:
//Returns the tile at the given x and y positions.

Tile Map::getTile(int x, int y){
	return this->tile[(16*y*this->xTile*16)+(x*16)];
}
//Initializes the dynamic array to the size given by the constructor.
Map::Map(int width, int height): tile(new Tile[width*height])
{
	this->xTile = width;
	this->yTile = height;

Tile.h:

class Tile{
public:
	int x, y;
	//0 = Solid, 1 = not solid - pass under, 2 = not solid - pass over.
	int solid;
	//Position of the tile on the chipset.
	int CPosX;
	int CPosY;
	bool passDir[4];
	
	Tile();
};

ref class MTile{
public:
	Tile * _t;
	MTile();
}

This is the line I'm getting the error at:

project._p->it->getTile(x, y).CPosX = panel2->Location.X;

So, as you can see, CPosX and X in this line are both integers, so why am I getting this error? Or am I misinterperting the reason for the error?

I would really like for some assistance on this issue.

Thanks for any and all helpers.

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by KazenoZ
0

I'm not sure I'm following the intent of this very well. The reason for the error is that the compiler cannot use a pointer as a physical location for storage of an int.

The function Map::getTile() looks like it's really returning a pointer to a Tile and this is probably the key to your problem.

0

When you call getTile, you get a newly created value of type Tile. Your statement

project._p->it->getTile(x, y).CPosX = panel2->Location.X;project._p->it->getTile(x, y).CPosX = panel2->Location.X;

calls getTile to obtain such an object, then changes the CPosX member of that object, and finally throws the object away. Fortunately, C++ doesn't let you do that; because if it did, you'd never find your problem :-)

I am guessing that you want to make your getTile function return a Tile& rather than a plain Tile.

0

Thank you both for the answers, I tend to mess up pointers alot for some reason D:

It works now, thanks alot.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.