编译器好像是吧“<<”这个符号认错了
以下是原码:#include<iostream>
#include<string.h>
using namespace std;
class CBuliding
{
string name;
public:
void set(string strName);
void display();
};
void CBuliding::display()
{
cout<<"建筑是"<<name<<endl;// 就是这里,书上说这里是内联函数。
}
void CBuliding::set(string strName)
{
name=strName;
}
class CBridge:public CBuliding
{
float length;
public:
void setLength(float l)
{
length=l;
}
void display()
{
CBuliding::display();
cout<<"其长度是"<<length<<"米"<<endl;
}
};
void main()
{
CBuliding buliding;
CBridge bridge;
buliding.set("中国古建筑");
buliding.display ();
bridge.set("中国赵州桥");
bridge.setLength(static_cast<float>(60.40));
bridge.display();
return;
}
【cout<<"建筑是"<<name<<endl;】
这里如果是把name去掉的话就能编译通过。如果加进去就会提示:
binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable co
nversion)
实在是想不通是哪里错了: