user3733748
user3733748

Reputation: 25

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

im new to c++ and I wanted to call a class/function from a second .cpp page.

error:

error C2512: 'QueryAuthServer' : no appropriate default constructor available

new.h

class QueryAuthServer : public CNtlSession
{
public:
    void SendCharLogInRes(CNtlPacket * pPacket);
}

new.cpp

void QueryAuthServer::SendCharLogInRes(CNtlPacket * pPacket)
{
    ....
}

main.cpp

QueryAuthServer C;
C.SendCharLogInRes(pPacket);

The error is at the main.cpp I already used google and viewed othr pages with the same error but I dont understand how to solve the bug. Ive read, that something about "C" should be missing but I dont know what..

Upvotes: 1

Views: 5630

Answers (1)

Armen Tsirunyan
Armen Tsirunyan

Reputation: 132974

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!*/)
    {
    } 
};

Upvotes: 5

Related Questions