class pointer as a private member?
I don't see where can I add "code tag" to my attached codes, do I need to post a certain # to be able to do it?
Here is my question, I have two classes, I want to call a public function in the first calss which in turn calls the second class. I"thought" I can save the pointer of the second class as a private member of the first class so it can be availabe when was called , but apparently no, the following codes cause a run time error, could someone explain to me where did I do wrong?
Thanks very much for your help,
#include "stdafx.h"
class MySecondCls
{
public:
MySecondCls()
{Inta = 0;};
void AddToInta(int i)
{ Inta = Inta + i;
}
int PrintInta()
{
return Inta;
}
private:
int Inta;
};
class MyFirstCls
{
private:
int j;
MySecondCls *my_object;
public:
MyFirstCls()
{
MySecondCls *my_object = new MySecondCls;
j = 5;
};
inline void CallSecondCls(int i)
{
my_object->AddToInta(i);
printf("number = %d \n" , my_object->PrintInta());
}
~MyFirstCls()
{
delete my_object;
}
};
void main()
{
MyFirstCls *myCls = new MyFirstCls;
myCls->CallSecondCls(5);
myCls->CallSecondCls(5);
delete myCls;
}

