一段C++程序 谁给改改错误 大体解释下程序 谢谢哥哥!

来源:百度知道 编辑:UC知道 时间:2024/06/05 20:17:33
#include <iostream>
#include <string>
using namespace std;

class person
{
public :
person(string name = "", string id = ""):m_name(name), m_id(id){}
virtual string get() const {return m_name;}//虚函数
~person(){}
protected :
string m_name;//姓名
string m_id;//身份证号
};

class student:public person//类的继承
{
friend istream & operator >> (istream &in, student &stu);//友元运算符重载
public :
student(string name = "", string id = "", string num = ""):person(name, id), m_num(num){}
string get() const {return m_num;}
private :
string m_num;//学号
};
istream & operator >> (istream &in, student &stu)
{
cout << "input student infomation:" << endl;
cout << "name:";
in >> stu.m_name;
cout << "id:";
in >&

不知道楼主用的什么编译器,我在VC6.0下提示有错,说友元函数不能访问student的m_name等成员,但我在cygwin下调试正常,看来是编译器的原因。就我的知识来看,这段代码是符合标准C++的,可能是你的编译器对C++的支持不完全。

程序错??
是 第 3 排 的 第 5个 英文

我看这程序真的没有问题啊。。。。。。。。。。。

你试试把 #include <iostream>

该成 #include <iostream.h>

应该可以吧!!

有的VC6.0版本不支持友元函数,我记得好像要把using namespace std;去掉, #include <iostream>改为#include <iostream.h>