passing by reference

closed account (SjEq5Di1)
Hi,

I'm new at C++ and I'm working with someone else's data structure. I've been using Visual C++ 2010 Express. I've had to create objects using their constructor and then manually modify the fields of that object, as well as call functions on the object, and I've used a pointer with the normal format:

Object* newobject = new Object()

and have been working with it using the -> operator (rather than the . one).

However, now I need to pass it as an argument to a method that looks like this:

Method(&object)

And when I try to pass it like so:

someotherobject.Method(newobject);

I get a compiler error:

cannot convert parameter 1 from 'Object *' to 'Object &'

I cannot rewrite the code for the method -- only how I deal or instantiate the object. How can I fix this?

Thanks!

Please use [code][/code] tags to show code, like this:

someotherobject.Method(*newobject);
Topic archived. No new replies allowed.