有关下面 C++ 代码的说法,错误的是( )。
#include <iostream>
#include <string>
using namespace std;
class MyStr {
string data;
public:
MyStr(string _data): data(_data) {}
};
int main() {
MyStr st("ABC");
cout << st << endl;
return 0;
}
- A. 代码
cout << st << endl;会报错,因为没有为MyStr类重载<<运算符。 - B. 第 行代码的
data是MyStr类的成员变量。 - C. 代码
MyStr st("ABC");不会报错,将执行构造函数。 - D. 代码
cout<< st.data <<endl;可输出ABC。