C++ cannot instantiate abstract class, object of abstract class not allowed

  c++

so this is base class : player.h
I’m getting an error saying that it cannot instantiate abstract class in main and C2559
object of abstract class type "Computer" is not allowed – E0322

idk why but my computer class isn’t showing up even though I declared the virtual void/void the same way

so my main would just be

 GameMechanics game;
 Computer comp; 

    class Player 
{
protected:
    Board board;
    Ship carrier; //5
    Ship battleship;// 4
    Ship cruiser;// 3
    Ship submarine;//3 
    Ship destroyer; //2

public:
    Board& getBoard();
    void setBoard(int x, int y, int hit);

    void hit(Board& board, int);
    bool hasWon();
   
    //using polymorphism for inheritance with pure implementation
    virtual void setShip(Ship&, int) = 0;
    virtual void getshipStats() = 0;
    virtual void attackShips(Board&) = 0;
   
};

and now my computer.h

    class Computer : public Player 
{
public:
    
    Computer();

    //computer specific 
    int randomNumbers();
    char randomPositions();

    void getShipStats();
    void setShips(Ship&, int);
    void attackShips(Board&);

    void setBoard(int x, int y, int hit);
    void shipPlaced(Ship&, int);

};

I’m also having the same issue with my GameMechanics.h file too
They both state that there’s no overrider. Any tips?

class GameMechanics :public Player
{ 
public:
    GameMechanics();


    void getShipFile();

    int changeInt(char);

    void getShipStats(ifstream&, string&, string&, char&, int&, int&);
    void attackShips(Board&);
    void setShip(Ship&, int);

    //to allow player to set in own ships 
    void setOwnShips(Ship&, int&, int&);
};

Source: Windows Questions C++

LEAVE A COMMENT