我記得我曾經是能夠做到這一點,必須按預期工作變量名:使用「這 - >」,將內部構造
class foobar
{
public:
foobar(int x, int y)
{
x = x; //the variables x, y belonging to the class got correctly initialized
y = y;
}
private:
int x, y;
};
以上在大約200X工作在微軟的Visual C++ 6.0還有一些更新的版本,我相信。
但現在我必須這樣做在微軟工作室2013年和我必須使用this->
,因爲這樣的:
class foobar
{
public:
foobar(int x, int y)
{
this->x = x; //the other way no longer initializes class vars
this->y = y;
}
private:
int x, y;
};
是否有語言規範變化或微軟編譯器的變化?
自VC6以來,出現了兩種巨大的語言變化。但是我不知道它是遵循1998年以前的標準規則還是自己的規則,因爲我還不夠年齡,無法在1998年之前使用C++。第一個版本肯定是錯誤的,因爲至少是C++ 98。 – 2014-11-06 16:52:44
你沒有使用[初始化列表](http://www.cprogramming.com/tutorial/initialization-lists-c++.html)的原因? @Mgetz在這裏不適用,你有條件倒退 – clcto 2014-11-06 16:56:32