I'm new to C++, I have more experience in OCaml and Python. I want to learn C++ by making a program playing "Morpion Solitaire". My beginnings are a bit difficult.
In the following code :
typedef enum {NORTH, NORTHEAST, EAST, SOUTHEAST} direction;
char deltax[4] = { 0, 1, 1, 1};
char deltay[4] = { 1, 1, 0, -1};
class Coords {
private:
char x,y;
public:
Coords(char xx,char yy){
x = xx;
y = yy;
};
char get_x() const { return x;}
char get_y() const { return y;}
};
class Line {
private:
Coords orig;
direction dir;
Coords newcross;
public:
Line(char x1, char y1, direction d, char x2, char y2) {
orig = Coords(x1,y1);
dir = d;
newcross = Coords(x2,y2);
};
Coords nthpoint(char n) {
char x,y;
x = orig.get_x() + n*deltax[dir];
y = orig.get_y() + n*deltay[dir];
return Coords(x,y);
};
};
the compiler tells me this :
nico@gaston:~/Travail/Cplusplus/morpion++$ g++ -c morpion.cc
morpion.cc: In constructor ‘Line::Line(char, char, direction, char, char)’:
morpion.cc:29:57: error: no matching function for call to ‘Coords::Coords()’
Line(char x1, char y1, direction d, char x2, char y2) {
^
morpion.cc:29:57: note: candidates are:
morpion.cc:11:3: note: Coords::Coords(char, char)
Coords(char xx,char yy){
^
morpion.cc:11:3: note: candidate expects 2 arguments, 0 provided
morpion.cc:6:7: note: Coords::Coords(const Coords&)
I don't understand the message. I have given a 2 argument constructor for class Coords
, but the compiler keeps telling me that orig = Coords(x1,y1)
calls the constructor with 0 arguments.
What did I miss ?
Remark : I initially put the declarations of Coords and Line in different files, and thought I did not use the proper #include
, but putting everything in one single file didn't solve the problem...