C++ : Connecting a member of a class to its definition -


i'm new c++, have more experience in ocaml , python. want learn c++ making program playing "morpion solitaire". beginnings bit difficult.

in 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 :

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 call ‘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 message. have given 2 argument constructor class coords, compiler keeps telling me orig = coords(x1,y1) calls constructor 0 arguments.

what did miss ?

remark : put declarations of coords , line in different files, , thought did not use proper #include, putting in 1 single file didn't solve problem...

line(char x1, char y1, direction d, char x2, char y2)   : orig(x1,y1), dir(d), newcross(x2, y2) {} 

coords doesn't have default constructor. original code attempts first default-construct orig, assign new value it. lack of default constructor, first step fails.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -