c ++ newbie error C2512:没有合适的默认构造函数可用

时间:2014-06-12 10:58:34

标签: c++

我是c ++的新手,我想从第二个.cpp页面调用一个类/函数。

错误:

  

错误C2512:'QueryAuthServer':没有合适的默认构造函数   可用

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);

错误发生在main.cpp 我已经使用谷歌和查看othr页面相同的错误,但我不明白如何解决这个错误。我读过,关于“C”的东西应该丢失,但我不知道是什么......

1 个答案:

答案 0 :(得分:5)

如果您的基类 - CNtlSession没有默认的构造函数,那么编译器将无法为派生类 - QueryAuthServer自动生成默认的构造函数。如果你需要一个,你必须自己编写,准确地说明你希望如何初始化基类子对象。

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