Search code examples
c++classoopconstructordefault

error:no matching fucntion for call to 'Square::Square(SquareColor&,Location*)'


I'm trying to make a chess game in C++ and I have an error I can't resolve

where the error is:

for(auto file : all_E)
    {
        Square newSquare= new Square(currentColor, new Location(file,i));
        boardSquares[i][column]=newSquare;
    }

These are the Square and Location Classes

class Square {
    SquareColor squareColor;
    Location location;
    bool isOcuppied;

public:
    Square();
    Square(SquareColor sqCol, Location loc );
    void reset();
    bool isOccupied();
    void setOccupied(bool occupied);
    SquareColor getSqCol();
    Location getLoc();
    char* toString();
};

class Location {
    File file;
    int rankk;

public:
    Location();
    Location(File _file, int _rankk);
    File getFile();
    int getRank();
};

I read about this error, and I tried to add the the default constructor Square() and Location(), but it didn't work.


Solution

  • You are constructing a pointer (Location*), not an object (Location), which is why the constructor does not match.

    Remove the new:

    Square newSquare = Square(currentColor, Location(file,i));