Reputation: 377
I'm passing references to pointers in order to use virtual functions.
Option 1 does what I intended and calls the appropriate derived class virtual function. Option 2 does not, suggesting no reference was passed. Since this does compile, then what does &
mean in this context if not pass by reference?
1.
Derived aDerived;
Derived *pDerived = &aDerived;
2.
Derived *pDerived = &Derived();
Upvotes: 0
Views: 143
Reputation: 33944
In option 2 you are attempting to take the address of an rvalue
. This should fail to compile with:
error: lvalue required as unary ‘&’ operand
Upvotes: 1