我試圖訪問一個成員結構變量,但我似乎無法得到正確的語法。 這兩個編譯錯誤公關。訪問是: 錯誤C2274:'功能風格強制轉換':非法作爲'。'的右側。運算符 錯誤C2228:'.otherdata'的左邊必須有class/struct/union 我試過了各種更改,但都沒有成功。C++:從類指針訪問成員結構的語法
#include <iostream>
using std::cout;
class Foo{
public:
struct Bar{
int otherdata;
};
int somedata;
};
int main(){
Foo foo;
foo.Bar.otherdata = 5;
cout << foo.Bar.otherdata;
return 0;
}
謝謝,完全忘了那個。並且像魅力一樣工作。 – 2009-05-27 11:07:37
代碼不完全相同。在第一個示例中,Bar結構的名稱實際上是Foo :: Bar。 – 2009-05-27 11:09:09