【发布时间】:2023-03-09 15:13:01
【问题描述】:
我正在尝试访问成员结构变量,但我似乎无法正确使用语法。 这两个编译错误pr。访问是: 错误 C2274:“函数样式转换”:作为“。”的右侧是非法的操作员 错误 C2228:“.otherdata”左侧必须有类/结构/联合 我尝试了各种更改,但都没有成功。
#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;
}
【问题讨论】: