标题:关于复数的操作,编译器通过不了。
只看楼主
qq710467272
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-3-30
结帖率:100%
已结贴  问题点数:20 回复次数:4 
关于复数的操作,编译器通过不了。
#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
天使梦魔
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:37
帖 子:564
专家分:2754
注 册:2007-8-29
得分:20 
没看,先编译了一次
然后出现
1>aaaaa.cpp
1>.\aaaaa.cpp(49) : warning C4172: 返回局部变量或临时变量的地址
1>正在链接...
1>aaaaa.obj : error LNK2001: 无法解析的外部符号 "public: __thiscall A::A(double,double)" (??0A@@QAE@NN@Z)
警告是说的很明白了
错误说的是无法连接到某个函数
一看,恩,果然没有定义过程,只有个声明
A(double i=0,double j=0){};

程序输出一堆数字??????
2014-03-30 22:08
qq710467272
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-3-30
得分:0 
回复 4楼 天使梦魔
请问用的是什么编译器哇?
2014-04-01 14:38



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




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

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