A
Alfredo Vernucci
Hello,
I am experimenting with C++0x and I have some problems with move operations.
I have a class that shall not be moved and therefore I have deleted from it both the move constructor and the move assignment operator. But then I have discovered that I cannot return instances of that class by value.
With the example reported here below, gcc 4.6 provides the following error message: error: use of deleted function 'A::A(A&&)' (btw, I get a similar error message also with MSVC2010).
class A
{
public:
A() {}
A(const A&) {}
A(A&&) = delete;
auto operator=(A&&) -> A& = delete;
auto foo() -> A
{
return A();
}
};
In this example, since the move constructor is not available, I would have expected the copy constructor to be called when foo() returns. But clearly this is not the case.
Question: what should I do if I want to forbid move operations for a class and yet be able to return instances of that class by value?
Thanks in advance,
Alfredo
I am experimenting with C++0x and I have some problems with move operations.
I have a class that shall not be moved and therefore I have deleted from it both the move constructor and the move assignment operator. But then I have discovered that I cannot return instances of that class by value.
With the example reported here below, gcc 4.6 provides the following error message: error: use of deleted function 'A::A(A&&)' (btw, I get a similar error message also with MSVC2010).
class A
{
public:
A() {}
A(const A&) {}
A(A&&) = delete;
auto operator=(A&&) -> A& = delete;
auto foo() -> A
{
return A();
}
};
In this example, since the move constructor is not available, I would have expected the copy constructor to be called when foo() returns. But clearly this is not the case.
Question: what should I do if I want to forbid move operations for a class and yet be able to return instances of that class by value?
Thanks in advance,
Alfredo