24

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 } 
0

2 Answers 2

30

Just dereference the pointer, resulting in the lvalue:

somefun(*obj); 
Sign up to request clarification or add additional context in comments.

Comments

5

you just have to do :

somfunc(*obj); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.