Hello guys i have a logical problem…i had to do a kinda fo labyrinth and it work but then im trying to do it with classes…so here it is.
i have a function outside of main called void playeraction();
cout<<"\nAction : ";
cin>>action;
int prevX=posX;
int prevY=posY;
unsigned char space = {32};
switch (action)
{
case 'a':
if(grid[posX][posY-1]!='#')
{
posY--;
grid[prevX][prevY]=space;
system("cls");
break;
}
when its like this the character moves without any problem
now when i try to implimenet classes it doesnt
case 's':
if(grid[posX+1][posY]!='#')
{
Dragon obj;
obj.moveSouth(posX);
grid[prevX][prevY]=space;
system("cls");
break;
}
in dragon cpp
int Dragon::moveSouth(int posX)
{
return posX++;
}
any ideas why it doesn’t return the posX++??
In your code, there are some bugs.
First, for ‘posX++’, posX is increased after using its value. You should use ++posX to make it be increased before using.
Second, in the function, the memory of its arguments is on stack. They are temporary, not origin memory of the variables.
You can use reference for this code.