Angus schrieb:
> I have a function called subscribe which passes a pointer to a
> 'subscribing' object to a class which will call functions on this
> object.
>
> Here is the function:
> void CEventSelect::subscribe(CEventSelect* user)
> {
> m_subscriber = user
> m_coll.push_back(user);
> }
>
> I declare this member like this:
>
> CMySubscriber* m_subscriber;
>
> If I copy using = in this way, m_subscriber becomes invalid as soon as
> the subscribe function finishes.
Why will m_subscriber become invalid?
The method CEventSelect::subscriber gets only a pointer. At the end of
the scope of the subscribe method, the pointer will be deleted, but not
the user object itself. As you have copied the pointer to m_subscriber,
there is no obvious reason,why it should become invalid!?
>
> If I put object in eg a vector then it works fine. Because I suppose
> vector is doing a proper copy. How would I do a sim,ilar copy without
> having to use a vector?
If you have problems you have to post more code in order to specify the
reason for your problems.
greets Boris
|