2014-06-12 250 views
1

即时通讯新手,我想从第二个.cpp页面调用类/函数。C++新手错误C2512:没有适当的默认构造函数可用

错误:

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

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

回答

5

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

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