Link to home
Start Free TrialLog in
Avatar of trevena
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



ASKER CERTIFIED SOLUTION
Avatar of LucHoltkamp
LucHoltkamp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trevena
trevena

ASKER

>One more thing, I'm using BC5 witch is a ANSI-compliant compiler. If >your's not, it could be the source of the problem. (Tried to save money ?? >;) )

No