标题:输入输出运算符重载 不明错误 大家帮我下
只看楼主
oicq
Rank: 1
等 级:新手上路
帖 子:34
专家分:1
注 册:2010-9-22
结帖率:85.71%
 问题点数:0 回复次数:4 
输入输出运算符重载 不明错误 大家帮我下
#include<iostream.h>
class three_d
{
public :
    int x,y,z;
    three_d(int a, int b,int c)
    {
        x=a;
        y=b;
        z=c;
    }
    friend istream &operator>>(istream &input,three_d &ob);
    friend ostream &operator<<(ostream &output,three_d &ob);
};
ostream &operator >>(ostream &output,three_d &ob)
{
   output<<ob.x<<"######"<<ob.y<<"######"<<ob.z<<"######";
   return output;
}
istream &operator<<(istream &input,three_d &ob)
{
    cout<<"Enter x y z   value :\n";
    input>>ob.x>>ob.y>>ob.z;
    return input;
}
void main()
{
    three_d obj(10,20,30);
    cout<<obj;
    cin>>obj;
    cout<<obj;
}
--------------------Configuration: 1111111111111 - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol "class istream & __cdecl operator>>(class istream &,class three_d &)" (??5@YAAAVistream@@AAV0@AAVthree_d@@@Z)
main.obj : error LNK2001: unresolved external symbol "class ostream & __cdecl operator<<(class ostream &,class three_d &)" (??6@YAAAVostream@@AAV0@AAVthree_d@@@Z)
Debug/1111111111111.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

1111111111111.exe - 3 error(s), 0 warning(s)
搜索更多相关主题的帖子: 输入 输出 重载 运算符 
2010-09-22 17:44
无名可用
Rank: 4
等 级:业余侠客
帖 子:79
专家分:259
注 册:2010-7-27
得分:0 
头文件的.h去掉.
加一句:using namespace std;
ostream &operator <<(ostream &output,three_d &ob)
{
   output<<ob.x<<"######"<<ob.y<<"######"<<ob.z<<"######";
   return output;
}
istream &operator>>(istream &input,three_d &ob)
{
    cout<<"Enter x y z   value :\n";
    input>>ob.x>>ob.y>>ob.z;
    return input;
}
仔细点就好了
2010-09-22 19:57
oicq
Rank: 1
等 级:新手上路
帖 子:34
专家分:1
注 册:2010-9-22
得分:0 
    3 Q   哥们你太帅了 嘿嘿     非常 感谢  !!!
 

                                                                  D.神罗天征
2010-09-22 20:00
oicq
Rank: 1
等 级:新手上路
帖 子:34
专家分:1
注 册:2010-9-22
得分:0 
     不行啊  改了之后
程序代码:
#include<iostream>
using namespace std;
class three_d
{
public :
    int x,y,z;
    three_d(int a, int b,int c)
    {
        x=a;
        y=b;
        z=c;
    }
    friend istream &operator>>(istream &input,three_d &ob);
    friend ostream &operator<<(ostream &output,three_d &ob);
};
ostream &operator >>(ostream &output,three_d &ob)
{
   output<<ob.x<<"######"<<ob.y<<"######"<<ob.z<<"######";
   return output;
}
istream &operator<<(istream &input,three_d &ob)
{
    cout<<"Enter x y z   value :\n";
    input>>ob.x>>ob.y>>ob.z;
    return input;
}
void main()
{
    three_d obj(10,20,30);
    cout<<obj;
    cin>>obj;
    cout<<obj;
}


 错误代码变了
--------------------Configuration: 1111111111111 - Win32 Debug--------------------
Linking...
main.obj : error LNK2001: unresolved external symbol "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class three_d &)" (??5@YAAAV?$basic_istream@DU?$
char_traits@D@std@@@std@@AAV01@AAVthree_d@@@Z)
main.obj : error LNK2001: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class three_d &)" (??6@YAAAV?$basic_ostream@DU?$
char_traits@D@std@@@std@@AAV01@AAVthree_d@@@Z)
Debug/1111111111111.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

1111111111111.exe - 3 error(s), 0 warning(s)

         我用的是 VC 6




[ 本帖最后由 oicq 于 2010-9-22 20:10 编辑 ]

                                                                  D.神罗天征
2010-09-22 20:04
oicq
Rank: 1
等 级:新手上路
帖 子:34
专家分:1
注 册:2010-9-22
得分:0 
ostream &operator >>(ostream &output,three_d &ob)
{
   output<<ob.x<<"######"<<ob.y<<"######"<<ob.z<<"######";
   return output;
}
istream &operator<<(istream &input,three_d &ob)
{
    cout<<"Enter x y z   value :\n";
    input>>ob.x>>ob.y>>ob.z;
    return input;
}
          终于看明白了 嘿嘿 谢啦哥们 还是我搞错了        

                                                                  D.神罗天征
2010-09-22 20:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-321121-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.151711 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved