| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 945 人关注过本帖
标题:输入输出运算符重载 不明错误 大家帮我下
取消只看楼主 加入收藏
oicq
Rank: 1
等 级:新手上路
帖 子:34
专家分:1
注 册:2010-9-22
结帖率:85.71%
收藏
 问题点数:0 回复次数:3 
输入输出运算符重载 不明错误 大家帮我下
#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
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
快速回复:输入输出运算符重载 不明错误 大家帮我下
数据加载中...
 
   



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

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