views:

83

answers:

2

In C++, when you have a function that takes a reference to an object, how can you pass an object pointer to it?

As so:

Myobject * obj = new Myobject();

somefunc(obj);  //-> Does not work?? Illegal cast??

somefunc(Myobject& b)
{
 // Do something
}
+3  A: 

Just dereference the pointer, resulting in the lvalue:

somefun(*obj);
GMan
+1  A: 

you just have to do :

somfunc(*obj);
Guillaume Lebourgeois