上课构造函数或破坏者之后的分号(;)
我目前正在使用传统来源维护和研究该语言,我想清除对班级中半彩的使用的混乱。
这是混乱使我震惊的地方。
class Base
{
public:
Base(int m_nVal = -1 ): nVal(m_nVal) {} // Confused here
virtual ~Base() {} // Confused here
public:
virtual void SomeMethod();
virtual int SomeMethod2();
protected:
int nVal;
};
class Derived : public Base
{
public:
Derived(int m_nVal):nVal2(m_nVal) {}; // Confused here
virtual ~Derived(){}; // Confused here
public:
virtual void SomeMethod();
virtual int SomeMethod2();
protected:/* Correction Here */
int nVal2;
};
我已经注意到,某些班级驱动器/构造师之后有半彩色,其中一些人没有,我确实知道,半彩是一个声明终结者。我的问题是,在构造函数或驱动器之后的半彩色告诉编译器特定的内容?还是不是真正重要的事情。
I am currently maintaining and studying the language using a Legacy Source,I want to clear up some confusion on the use of semi-colons inside a class.
Here is the bit where confusion strikes me.
class Base
{
public:
Base(int m_nVal = -1 ): nVal(m_nVal) {} // Confused here
virtual ~Base() {} // Confused here
public:
virtual void SomeMethod();
virtual int SomeMethod2();
protected:
int nVal;
};
class Derived : public Base
{
public:
Derived(int m_nVal):nVal2(m_nVal) {}; // Confused here
virtual ~Derived(){}; // Confused here
public:
virtual void SomeMethod();
virtual int SomeMethod2();
protected:/* Correction Here */
int nVal2;
};
I have noticed that some of the class destructors/constructors have a Semi-colon after them and some of them don't, I do understand that the a semi-colon is a is a statement terminator. My question is does the Semi-colon after the constructors or destructor tells something specific to the compiler? or is it something that doesn't really matter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
{}
在函数末尾base(int m_nval = -1):nval(m_nval){}
表示您对函数有完整的定义,而不是一个函数的定义单纯的声明如虚拟void somemethod();
也许当分布得更好时,它会更容易识别:
现在我们可以轻松地看到我们具有完整的函数定义(使用a 成员初始化器列表启动),功能永远不需要终止半元素。
The
{}
at the end of the functionBase(int m_nVal = -1 ): nVal(m_nVal) {}
means you have a complete definition of a function, not a mere declaration likevirtual void SomeMethod();
Perhaps it would be more recognizable when spread out a bit better:
Now we can easily see we have the full function definition (with a member initializer list to boot) and functions never require a terminating semicolon.
(或之前)成员函数定义没有。†
在(但不是之前)成员函数声明之后,这是强制性的。
'可能只是一个监督。
†:除非定义没有任何身体:
After (or before) a member function definition it does not.†
After (but not before) a member function declaration it is mandatory.
'Probably just an oversight.
†: Unless the definition has no body: