+ 1
Pass base pointer reference
Please refer code below: https://code.sololearn.com/cl48KxgAsSq1 Can we achieve the update method which takes base pointer as reference? Doing so works fine in case of Base* pb , but getting compile time error for scenario of Derived* pb. How to achieve this?
3 ответов
+ 4
This is because your Derived* pointer gets casted to a Base* on line 48. Since the casted pointer is an rvalue, you can't pass it to a function that takes lvalue reference.
Assigning the Derived* pointer to a Base* pointer first and then passing that will work
https://code.sololearn.com/cEpYOhei3A1W/?ref=app
0
I ran it just now and got no error. If I understood the code correctly, everything worked fine.
Could you pls elaborate on the issue?
0
Change update function signature as below and you will get an error:
void Update(Base*& pb)