Which is the right way to call base class move ctor?
this (works in MSVC2010, but not in CBuilder2010):
struct Foo
{
Foo(Foo&& other) { }
};
struct Bar : public Foo
{
Bar(Bar&& other) : Foo((Foo&&)other) { }
};
or (works in CBuilder2010, but not in MSVC2010):
struct Foo
{
Foo(Foo&& other) { }
};
struct Bar : public Foo
{
Bar(Bar&& other) : Foo(&other) { }
};
or, are they both wrong? If so, what’s the right way (in terms of what’s specified in the C++0x standards)?
Note: I can’t figure out how to get it to work in CBuilderXE (both versions don’t work).
The first option looks logical although I would spell it
std::forward<Bar>(other).I have no idea what causes CBuilder to think that the type of
&otherisBar&&and notBar*.Basically what’s happening here is that once an rvalue reference is named it is no longer an rvalue reference, that’s what
std::forwardis for, it maintains the rvaluness (to coin a phrase), so when you call: Foo(other)you’re calling the copy constructor rather than the move constructor.This should be the idiomatic (and standard compliant) way to achieve what you’re trying to do (unless I’m badly misunderstanding the FCD).