hello firstly.when i compiler this program ,i get run-time error..i couldnt corect it.can u help me?thnx.
i think i must do, *p=*(b.p); for p=b.p; but still have run-time eror.
pls say me.
here is the program....
#include<iostream.h>
class A{
int ai;
public:
A();
A(A&);
~A();
void operator=(A);
int fA() const {return ai;}
};
class B{
A a;
A *p;
public:
B(int);
B(B&);
~B();
A &f5(B);
B& operator=(B& b);
};
A::A(){
cout<<"Message 1" <<endl;
ai=1;
}
A::A(A& a){
cout<<"Message 2" <<endl;
ai=a.ai;
}
A::~A(){
cout<<"Message 3" <<endl;
}
void A:perator=(A a){
cout<<"Message 4" <<endl;
ai=a.ai;
}
B::B(int i){
cout<<"Message 5" <<endl;
p=new A[i];
}
B::B(B& b){
cout<<"Message 6" <<endl;
p=b.p;
a=b.a;
}
B::~B(){
cout<<"Message 7" <<endl;
delete [] p;
}
A &B::f5(B b){
cout<<"Message 8" <<endl;
if(a.fA()>b.a.fA()) a=b.a;
return a;
}
void main(){
A a;
B b1(2),b2(1);
B b3=b1;
b3.f5(b2)=a;
b2=b1;
}