![]() |
#2
wp2319572013-08-19 14:38
这是汉化版vs2010的编译信息
1> 正在创建“Debug\t7.unsuccessfulbuild”,因为已指定“AlwaysCreate”。 1>ClCompile: 1> stdafx.cpp 1> t7.cpp 1>d:\c_source\t7\t7\t7.cpp(15): error C2556: “std::istream &operator >>(std::istream &,F &)”: 重载函数与“void operator >>(std::istream &,F &)”只是在返回类型上不同 1> d:\c_source\t7\t7\t7.cpp(8) : 参见“operator >>”的声明 1>d:\c_source\t7\t7\t7.cpp(15): error C2040: “operator >>”:“std::istream &(std::istream &,F &)”与“void (std::istream &,F &)”的间接寻址级别不同 1>d:\c_source\t7\t7\t7.cpp(17): error C2678: 二进制“>>”: 没有找到接受“std::basic_istream<_Elem,_Traits>”类型的左操作数的运算符(或没有可接受的转换) 1>d:\c_source\t7\t7\t7.cpp(19): error C2556: “std::ostream &operator <<(std::ostream &,const F &)”: 重载函数与“void operator <<(std::ostream &,const F &)”只是在返回类型上不同 1> d:\c_source\t7\t7\t7.cpp(9) : 参见“operator <<”的声明 1>d:\c_source\t7\t7\t7.cpp(19): error C2040: “operator <<”:“std::ostream &(std::ostream &,const F &)”与“void (std::ostream &,const F &)”的间接寻址级别不同 1>d:\c_source\t7\t7\t7.cpp(25): error C2264: “operator >>”: 函数定义或声明中有错误;未调用函数 1>d:\c_source\t7\t7\t7.cpp(25): error C2088: “>>”: 对于 class 非法 1>d:\c_source\t7\t7\t7.cpp(26): error C2264: “operator <<”: 函数定义或声明中有错误;未调用函数 1>d:\c_source\t7\t7\t7.cpp(26): error C2088: “<<”: 对于 class 非法 1> 1>生成失败。 1> 1>已用时间 00:00:02.93 ========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ========== |
#include<iostream>
#include<string>
using namespace std;
class F{
int n;
int d;
friend void operator>>(istream& in,F& f);
friend void operator<<(ostream& out,const F& f);
public:
F(int n=0,int d=1):n(n),d(d){};
~F(){};
};
istream& operator>>(istream& in,F& f){
char c;
in>>f.n>>c>>f.d>>endl;
}
ostream& operator<<(ostream& out,const F& f){
out<<f.n<<'/'<<f.d<<endl;
}
int main ()
{
F a;
cin>>a;
cout<<a;
return 0;
}
错误提示:C:\Users\kjk\c编程\输入与输出.cpp(17) : error C2248: 'n' : cannot access private member declared in class 'F'
C:\Users\kjk\c编程\输入与输出.cpp(6) : see declaration of 'n'
C:\Users\kjk\c编程\输入与输出.cpp(17) : error C2248: 'd' : cannot access private member declared in class 'F'
C:\Users\kjk\c编程\输入与输出.cpp(7) : see declaration of 'd'
C:\Users\kjk\c编程\输入与输出.cpp(17) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion)
C:\Users\kjk\c编程\输入与输出.cpp(20) : error C2248: 'n' : cannot access private member declared in class 'F'
C:\Users\kjk\c编程\输入与输出.cpp(6) : see declaration of 'n'
C:\Users\kjk\c编程\输入与输出.cpp(20) : error C2248: 'd' : cannot access private member declared in class 'F'
C:\Users\kjk\c编程\输入与输出.cpp(7) : see declaration of 'd'
C:\Users\kjk\c编程\输入与输出.cpp(25) : error C2593: 'operator >>' is ambiguous
C:\Users\kjk\c编程\输入与输出.cpp(26) : error C2593: 'operator <<' is ambiguous
执行 cl.exe 时出错.
输入与输出.exe - 1 error(s), 0 warning(s)