class apple{
private:
int a;
int b;
public :
void input(int x,int y){a=x;y=b;}
void dis (){cout<<"a="<<a<<" b="<<b<<endl ;}
apple &operator+(const apple *c);
};
apple &apple :: operator+(const apple *c)
{
apple *d;
d = new apple();
d->a = a+ c->a;
d->b = b + c->b;
return *d ;
}
int main()
{
apple *a,*b,*c;
a = new apple();
b = new apple();
c = new apple();
a->input(1,2);
b->input(3,4);
c = a + b ;
system("pause");
return 0 ;
}
compiler 是 dev c++ 4.9.9.2作者: dh3014 時間: 2013-11-13 09:01 PM
痾~ 好像不是這個問題欸....
就算我把那些變數放在 public 好像也是錯誤作者: snowflying 時間: 2013-11-13 11:05 PM
1. dev c++ 4.9.9.2 不是 compiler
2. #include<iostream>
#include<cstdio>
3. std::cout 或 using namespace std;
4. *c = *a + b ; (根據 apple &operator+(const apple *c);)
不過不建議用這種方式 作者: johnwanz 時間: 2013-11-14 09:35 AM