运行时错误需要“;”吗?
我试图使用继承来创建一个从 runtime_error
派生的类,但我不断收到错误,即使这是练习中使用的确切代码以及本书中的示例。这是代码:
class DivideZeroEx : public runtime_error
{
public:
DivideZeroEx()
runtime_error( " attempt to divide by zero" )
};
现在我收到一个错误,指出它需要一个 ;在runtime_error(“尝试除以零”)行之前。
I am trying to use inheritance to create a class derived from runtime_error
, but I keep getting an error even though this is the exact code used in exercises and as an example from the book. Here is the code:
class DivideZeroEx : public runtime_error
{
public:
DivideZeroEx()
runtime_error( " attempt to divide by zero" )
};
Now I get an error stating that it expects a ; before the runtime_error("attempt to divide by zero") line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
调用基类构造函数的语法应该是:
The syntax for calling your base class constructor should be:
您正在尝试调用成员初始值设定项列表中的基类构造函数,语法为:
You are trying to call the Base class constructor in Member Initializer List, the syntax is:
在这种情况下,它并没有节省太多,但是如果您要在整个类中按名称使用
runtime_error
,那么将来更换基类会更容易。In this instance it doesn't save much, but if you were to use
runtime_error
by name throughout your class, this is much easier to swap out the base in the future.