"No Appropriate Default Constructor Available"--Why Is the Default Constructor Even Called

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.

No appropriate default constructor available--Why is the default constructor even called?

Your default constructor is implicitly called here:

ProxyPiece::ProxyPiece(CubeGeometry& c)
{
cube=c;
}

You want

ProxyPiece::ProxyPiece(CubeGeometry& c)
:cube(c)
{

}

Otherwise your ctor is equivalent to

ProxyPiece::ProxyPiece(CubeGeometry& c)
:cube() //default ctor called here!
{
cube.operator=(c); //a function call on an already initialized object
}

The thing after the colon is called a member initialization list.

Incidentally, I would take the argument as const CubeGeometry& c instead of CubeGeomety& c if I were you.

No appropriate default constructor available in C++11

You should typically just initialize the objects in the initializer list instead of default-constructing them and then assigning to them.

However, there's no reason why the compiler should accept a user-written empty default constructor over a defaulted one.

The most likely explanation is that SomeObj has no default constructor, or possibly that it is explicit.

c++ newbie error C2512: no appropriate default constructor available

If your base class - CNtlSession does not have a default contructor, then the compiler will not be able to automatically generate a default contructor for your derived class - QueryAuthServer. If you need one, you have to write it yourself, indicating exactly how you want your base class subobject initialized.

class QueryAuthServer : public CNtlSession
{
public:
QueryAuthServer() :CntlSession(/*PROVIDE ARGUMENTS HERE!*/)
{
}
};


Related Topics



Leave a reply



Submit