#ifndef Unit_h
#define Unit_h
#include <stdio.h>
#include <stdlib.h>
#include <string>
//#include "Student.h"
//#include "Node.h"
class Unit
{
public:
// Default constructor
Unit();
// Constructor that specifies a unit
Unit(int h, int a, int w, int c, int m, int p, int r, bool l, int x, int y);
// Unit moves across arena, returns whether it's a legal movement. Takes in coordinates as arguments.
bool Move(char board[], int x, int y);
//....there's also setter and getter functions, don't need to post everything
private:
int health;
int armor;
int wait;
int counter;
int move;
int power;
int range;//?????? will have to be a set of coordinates
bool living;
int xpos;
int ypos;
};
#endif
Yeah, I thought the second one would be the right one.
Here's the error:
Unit.cpp: In member function âbool Unit::Move(char*, int, int)â:
Unit.cpp:63:33: error: invalid types âchar[int]â for array subscript
Unit.cpp:66:33: error: invalid types âchar[int]â for array subscript
Well this is different. Those lines do not work because the variable board refers to a pointer to char array. If you want those lines to work, the function:
bool Unit:: Move(char board[], int x, int y)
Should instead be:
bool Unit:: Move(char *board[], int x, int y)
or bool Unit:: Move(char board[][], int x, int y)
or bool Unit:: Move(char **board, int x, int y)
Now in main, you should call the function the way you called it previously and that should get rid of the errors
I actually looked at that exact article before making this topic, but I found it unhelpful because it deals with single-dimensional arrays, and also my array is being passed around three different programs (Unit.h, Unit.cpp, Game.cpp).
I also did what you said...and it still refuses to compile.
When you said call the function the way you called it previously, I presume you meant the way I had it in they very first post?
These are my three lines of interest:
From the Unit.h bool Move(char board[], int x, int y);
From the Unit.cpp bool Unit:: Move(char *board[], int x, int y)
From the Game.cpp Alexander.Move(board[r][c], 3, 9);
I think it's worth noting that I also did this (and it doesn't work either)
I figured that may be the case, and I had tried it out as well, and it still didn't compile.
This is what I have:
From Unit.h bool Move(char *board[], int x, int y);
From Unit.cpp bool Unit:: Move(char *board[], int x, int y)
From Game.cpp Alexander.Move(board, 3, 9);
Exactly what you said, right??
I don't get why it won't work... I don't know if this will help, but here's the error:
Game.cpp: In function âint main()â:
Game.cpp:39:28: error: no matching function for call to âUnit::Move(char [15][15], int, int)â
Game.cpp:39:28: note: candidate is:
In file included from Game.cpp:12:0:
Unit.h:21:8: note: bool Unit::Move(char**, int, int)
Unit.h:21:8: note: no known conversion for argument 1 from âchar [15][15]â to âchar**â