trevena
asked on
Intilasing References
Hi,
How do you intialise refrences, when they occur as member functions.
ie, the case I have boils down to (if you ignore the application specifics)
int j;
class malc
{
public:
malc():m_i(* (new int))
~malc{delete m_i;}
int & m_i;
}
complier says that I need to initiliase the reference to a non temp int. The best way I thought of was the constructor shown above, with the corresponding destructor.
I don't now if this is the right way to go about it, or if I'm completely on the wrong track. So if you could fix the above code, or just show me the more correct way of doing it as it just doesn't look right to me, or say my code is wonderful and be done with it :)
Thanks
Malcolm
How do you intialise refrences, when they occur as member functions.
ie, the case I have boils down to (if you ignore the application specifics)
int j;
class malc
{
public:
malc():m_i(* (new int))
~malc{delete m_i;}
int & m_i;
}
complier says that I need to initiliase the reference to a non temp int. The best way I thought of was the constructor shown above, with the corresponding destructor.
I don't now if this is the right way to go about it, or if I'm completely on the wrong track. So if you could fix the above code, or just show me the more correct way of doing it as it just doesn't look right to me, or say my code is wonderful and be done with it :)
Thanks
Malcolm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No