【发布时间】:2010-11-01 10:18:17
【问题描述】:
调用基类移动ctor的正确方法是什么?
这个(在 MSVC2010 中有效,但在 CBuilder2010 中无效):
struct Foo
{
Foo(Foo&& other) { }
};
struct Bar : public Foo
{
Bar(Bar&& other) : Foo((Foo&&)other) { }
};
或(在 CBuilder2010 中有效,但在 MSVC2010 中无效):
struct Foo
{
Foo(Foo&& other) { }
};
struct Bar : public Foo
{
Bar(Bar&& other) : Foo(&other) { }
};
或者,他们都错了吗?如果是这样,正确的方法是什么(根据 C++0x 标准中的规定)?
注意:我不知道如何让它在 CBuilderXE 中工作(两个版本都不工作)。
【问题讨论】:
-
Foo(&other)不应该编译,除非 Foo 有一个接受 Foo 指针的 ctor。
标签: c++ c++11 rvalue-reference move-semantics