Hi everyone,
I'm slowly starting to understand rvalue references and their benefits.
At the moment I'm creating a templated facade class, so I thought it might be the perfect time to use perfect forwarding. Unfortunately the compiler, gcc 4.6.3, is throwing me this error:
no known conversion for argument 1 from ‘type’ to ‘type&&’ |
Simplified version of the code I'm using:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
template <typename EntityType, typename EntityMapper>
class facade
{
public:
void read(EntityType&& e)
{
_mapper.read(std::forward<EntityType>(e));
}
private:
EntityMapper _mapper;
};
//used:
facade<person, personmapper> personfacade;
person p;
personfacade.read(p); //this fails
personfacade.read(std::move(p)); //this works
|
Could anyone please explain the difference, as to why this doesn't work, but the factory function on this page does: http://thbecker.net/articles/rvalue_references/section_08.html
To me they seem to be pretty much the same, but I must be missing something.
I'm trying to understand this, not to just copy things.
Thanks very much in advance.
All the best,
NwN