就是 : 在类中,类的 无论什么属性 public private 等,都是不可以在定义的时候赋初值 的
然后我 在类的属性中定义了一个 ofstream 类型的变量,指定了路径,然后就会给我抱着个错误,号和,真够傻的:"error: expected identifier before string constant"
原错误代码:
class XX {
public :
std::ofstream outfile("data.txt");
// 类中方法略
void run()
{}
}
正确的写法:
class XX {
public :
std::ofstream outfile;
// 类中方法略
void run()
{
outfile.open("data.txt");
}
}