class pointer as a private member?

Hi,

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;

}
[1492 byte] By [mph130] at [2007-11-20 11:38:56]
# 1 Re: class pointer as a private member?
MySecondCls *my_object = new MySecondCls;Discard the red text.
googler at 2007-11-9 1:25:53 >
# 2 Re: class pointer as a private member?
To format your code simply type

[ c o d e ] ... your code ... [ / c o d e ]

but without any spaces in the tags
sockman at 2007-11-9 1:27:04 >
# 3 Re: class pointer as a private member?
For that particular example, you might as well store an object of class MySecondCls as a member of class MyFirstCls (as opposed to a pointer to such an object).

Read the links below for info on custom tags and other important stuff.
treuss at 2007-11-9 1:28:03 >
# 4 Re: class pointer as a private member?
Sorry for off-topic.
I request site Admin to to provide a button for code tag.
What i mean is the user selects the code which is to be code tagged, then hits the 'code tag' button. The user need not type ....

See the attached image for what I mean.
Jacko123 at 2007-11-9 1:29:06 >
# 5 Re: class pointer as a private member?
It's off-topic and I doubt that the site-admins will read it. But just go to USER CP, click on Edit Options and set your editor to standard or advanced and you have your button.
treuss at 2007-11-9 1:30:01 >