Here you are creating a temporary object:
method(A()); // A() here is creating a temporary
// ie an un-named object
You can only get const&
to temporary objects.
So you have two options:
- Change the interface to take a const reference.
- Pass a real object.
So:
// Option 1: Change the interface
void method(A const& a) // You can have a const
// reference to a temporary or
// a normal object.
// Options 2: Pass a real object
A a;
method(a); // a is an object.
// So you can have a reference to it.
// so it should work normally.