run_time error

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....

I know how to debug but when all lines in main are executed
it gives error.so its difficult to find that error.
i know assignemnet operator as well but still has problem on it.
i know problem with p=b.p;
but cpouldnt corect.

The compiler won't create a default constructor for class B because you have declared other constructors. The compiler needs the default constructor in the copy constructor. You need to provide it.

-----------------------------------
This:

B::B(int i){
cout<<"Message 5" <<endl;
p=new A[i];

indicates p will be an array of i members of type A with memory for the elements declared on the free store. I suspect you want p to be pointer to a single type A with ai being assigned value i. If so I would try this:

B::B(int i){
cout<<"Message 5" <<endl;
p=new A(i);

wihich says use the A constructor with the single int argument rather than the default constructor for class A when declaring space.
----------------------------------------
Copy constructors can be tricky so I hope Iget it right. When classes have pointers embedded in them as members you have to be careful when copying or assigning one object to another. If you copy the original pointers contents, which is the address of the object being pointed to, this is called a memberwise or shallow copy. Unfortunately, if the original object being pointed to is destroyed before the copy then the pointer in the copy becomes a stray pointer. You should create a deep copy of the pointer, which copies the value at theaddress being pointed to, rather than the address in the pointer, when copying pointer members. In your case maybe something like this: