Here is a snippet of code which causes a C2664 error:
cannot convert argument 1 from 'std::unique_ptr<Component,std::default_delete<_Ty>>' to 'ComPtr &'
So why must a non-const reference be initialized with an lvalue? How to avoid this except by declaring a new variable?
#include <memory>
#include <list>
class Component {
};
using ComPtr = unique_ptr<Component>;
using ComList = list<ComPtr>;
ComList coms;
void addComponent(ComPtr&c) {
coms.push_back(c);
}
int main() {
addComponent(make_unique<Component>()); //Error here.
return 0;
}