【发布时间】:2015-03-16 14:49:49
【问题描述】:
我有一个看起来像这样的课程
class Rational{
public:
Rational(int p = 0, int q = 1) : p(p), q(q){};
private:
int p;
int q;
};
我的问题是关于成员变量和构造函数参数具有相同名称的初始化语法。 我现在知道这样做是合法的,但我的问题是: 如果我想要“干净”、易于掌握的代码,我想知道我是否可以像在 java 中那样做:
//Legal Java Code
this.q = q;
this.p = p;
//Is any of these legal C++ code (if so, which one)?
this.q(q);
this.p(p);
//or
this->q(q);
this->p(p);
即使我没有测试过,而且我可以测试它,我仍然想知道这样做的 C++ 约定。
【问题讨论】:
标签: c++11 syntax conventions