C++ – No appropriate default constructor available

In contrast to C#, this declaration;

Player player;

…is an instantiation of the type Player, which means that by the time you’re assigning it inside the constructor, it has already been constructed without a parameter.

What you need to do is to tell the class how to initialize player in what is called an initializer list that you append to the constructor header;

Game::Game(void) : player(100)
{
...

…which tells the compiler to use that constructor to initialise player in the first place instead of first using the default no-parameter constructor and then assigning to it.

Leave a Comment