这是我的 main.cpp 代码。输入是 3 个字符串,输出打印出传递给它的 3 个 String 对象的值和长度
void Display(const String &str1, const String &str2, const String &str3)
{
cout << "str1 holds \"";
str1.print(); // the error is here about the str1
cout.flush();
cout << "\" (length = " << str1.length() << ")" << endl;
cout << "str2 holds \"";
str2.print();
cout.flush();
cout << "\" (length = " << str2.length() << ")" << endl;
cout << "str3 holds \"";
str3.print();
cout.flush();
cout << "\" (length = " << str3.length() << ")" << endl;
}
这是错误:
错误 C2662:“String::print”:无法将“this”指针从“const String”转换为“String &”
这是在我的实现文件中:我在这里做错了吗?
void String::print()
{
cout << m_pName << ": ";
cout << (int)m_str1 << ", ";
cout << (int)m_str2 << ", ";
cout << (int)m_str3 << endl;
}