vendredi 29 janvier 2016

why an enum value can not be used as a rvalue?

I am using Clion 1.2.4 to build a C++ project based on C++11, when I try use make_shared function to create a shared_ptr object like this:

auto item = std::make_shared<Type>(EnumType::Value);

where Type is an struct with a constructor like this:

Type(EnumType t = defaultValue) { }

and the param of constructor is an enum type.

But the compiler give me an error :

parameter type mismatch: Expression must be rvalue.

So I want to know whether an enum value can be used as a rvalue to call a function? And why.

And if I use like this:

auto item = std::make_shared<Type>(std::move(EnumType::Value));

compiler will not show error. What the move function do? And is it right that using a constant value as the actual parameter of move function.

Aucun commentaire:

Enregistrer un commentaire