没有适当的默认构造函数可用。 (创建子类时) [英] no appropriate default constructor available . (when creating a child class)
本文介绍了没有适当的默认构造函数可用。 (创建子类时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一些自定义异常类。
I am creating some custom exception classes doing the following
class GXException
{
public:
GXException(LPCWSTR pTxt):pReason(pTxt){};
LPCWSTR pReason;
};
class GXVideoException : GXException
{
public:
GXVideoException(LPCWSTR pTxt):pReason(pTxt){};
LPCWSTR pReason;
};
当我创建GXVideoException扩展GXException时,得到以下错误
When I created GXVideoException to extend GXException, I get the following error
1>c:\users\numerical25\desktop\intro todirectx\godfiles\gxrendermanager\gxrendermanager\gxrendermanager\gxexceptions.h(14) : error C2512: 'GXException' : no appropriate default constructor available
推荐答案
您需要在您的派生构造函数的初始化器列表中调用您的基类构造函数。此外,由于您是从基类派生的,因此您不应使用相同的名称( pReason
)重新声明第二个变量。
You need to call your base class constructor inside your derived constructor's initializer list. Also since you are deriving from the base class you should not redeclare a second variable by the same name (pReason
).
class GXException
{
public:
GXException(LPCWSTR pTxt):pReason(pTxt){};
LPCWSTR pReason;
};
class GXVideoException : GXException
{
public:
GXVideoException(LPCWSTR pTxt)
: GXException(pTxt)
{}
};
这篇关于没有适当的默认构造函数可用。 (创建子类时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文