| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 462 人关注过本帖
标题:关于复数的操作,编译器通过不了。
取消只看楼主 加入收藏
qq710467272
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-3-30
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
关于复数的操作,编译器通过不了。
#include<iostream>
using namespace std;
class A
{     friend ostream& operator<<(ostream& object,const A& B);
      friend istream& operator>>(istream& object,const A& B);
private:
      double real;
      double image;
public:
      A(double i=0,double j=0);
      void set(double i,double j);
      
      A& operator+(const A& B);
      bool operator==(const A& B);
};
   void A::set(double i,double j)
   {
         real=i;image=j;
   }
   ostream& operator<<(ostream& object,const A& B)
   {
         object<<"(";
         object<<B.real;
         object<<",";
         object<<B.image;
         object<<")";
         return  object;
   }
   istream& operator>>(istream& object,const A& B)
   {
        char ch;
        object>>ch;
        object>>B.real;
        object>>ch;
        object>>B.image;
        object>>ch;
        return object;
   }
   A& A::operator+(const A& B)
   {
       A C;
       C.real=real+B.real;
       C.image=image+B.image;
       return C;
   }
   bool A::operator==(const A& B)
   {
       return((image=B.image)&&(real=B.real));
   }
         
   int main( )
   {
       A num1;
       A num2;
       A num3;
       num1.set(23,24);
       cout<<num1<<endl;
       cout<<num2<<endl;
       cout<<"Please input two nums"<<endl;
       cin>>num2;
       cout<<endl;
       cout<<num2;
       num3=num1+num2;
       cout<<num3;
       return 0;
   }

      
Configuration: 5 - Win32 Debug--------------------
Compiling...
5.cpp
D:\C++\复数加减\5.cpp(23) : error C2248: 'real' : cannot access private member declared in class 'A'
        D:\C++\复数加减\5.cpp(7) : see declaration of 'real'
D:\C++\复数加减\5.cpp(25) : error C2248: 'image' : cannot access private member declared in class 'A'
        D:\C++\复数加减\5.cpp(8) : see declaration of 'image'
D:\C++\复数加减\5.cpp(33) : error C2248: 'real' : cannot access private member declared in class 'A'
        D:\C++\复数加减\5.cpp(7) : see declaration of 'real'
D:\C++\复数加减\5.cpp(33) : error C2593: 'operator >>' is ambiguous
D:\C++\复数加减\5.cpp(35) : error C2248: 'image' : cannot access private member declared in class 'A'
        D:\C++\复数加减\5.cpp(8) : see declaration of 'image'
D:\C++\复数加减\5.cpp(35) : error C2593: 'operator >>' is ambiguous
D:\C++\复数加减\5.cpp(44) : warning C4172: returning address of local variable or temporary
D:\C++\复数加减\5.cpp(57) : error C2593: 'operator <<' is ambiguous
D:\C++\复数加减\5.cpp(58) : error C2593: 'operator <<' is ambiguous
D:\C++\复数加减\5.cpp(60) : error C2593: 'operator >>' is ambiguous
D:\C++\复数加减\5.cpp(62) : error C2593: 'operator <<' is ambiguous
D:\C++\复数加减\5.cpp(64) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.

5.obj - 11 error(s), 1 warning(s)
搜索更多相关主题的帖子: private include public double 编译器 
2014-03-30 11:15
qq710467272
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-3-30
收藏
得分:0 
大神们麻烦指点一下呗!!!
2014-03-30 17:04
qq710467272
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-3-30
收藏
得分:0 
为什么这么多人看,无人解答啊?
2014-03-30 19:09
qq710467272
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-3-30
收藏
得分:0 
回复 4楼 天使梦魔
请问用的是什么编译器哇?
2014-04-01 14:38
快速回复:关于复数的操作,编译器通过不了。
数据加载中...
 
   



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

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