重载输入输出的二义问题!
//:Student.h
#include<string.h>
class Student
{
public:
char * name;
int age;
char sex;
public:
Student(char* pname="no name",int n=20,char ch='f');
friend istream & operator >>(istream& in,Student& stu);
friend ostream & operator <<(ostream& out,const Student& stu);
};
Student::Student(char* pname,int n,char ch)
{
name=new char[strlen(pname)+1];
strcpy(name,pname);
age = n;
sex =ch;
}
istream & operator >>(istream & in,Student& stu)
{
in>>stu.name>>stu.age>>stu.sex;
return in;
}
ostream & operator <<(ostream & out,const Student& stu)
{
out<<"Name: "<<stu.name<<"\tAge: "<<stu.age<<"\tSex: "<<stu.sex<<endl;
return out;
}
#include<iostream>
using namespace std;
#include "Student.h"
int main()
{
Array<Student> stu(3);
for(int i =0 ;i<3;i++)
cin>>stu[i];
for(int j=0;j<3;j++)
cout<<stu[j];
system("PAUSE");
return EXIT_SUCCESS;
}
VC下编译竟然说有二义性!
不知道为何???
--------------------Configuration: ArrayTest - Win32 Debug--------------------
Compiling...
main.cpp
C:\Test\ArrayTest\main.cpp(17) : error C2593: 'operator >>' is ambiguous
C:\Test\ArrayTest\main.cpp(19) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.
ArrayTest.exe - 2 error(s), 0 warning(s)