0

please look at the following example code:

    class testo
{
public:
    testo()
    {
        cout << " default " << endl;
    }

    testo(const testo & src)
    {
        cout << "copy " << endl;
    }
    testo(const testo && src)
    {
        cout << "move" << endl;
    }
    testo & operator=(const testo & rhs)
    {
        cout << " assigment" << endl;
        return *this;
    }
    testo & operator= (const testo && rhs)
    {
        cout << "move" << endl;
    }

};

and this is my function and main code :

testo nothing(testo & input)
{
return input;
}

int main ()
{
testo boj1 ;
testo obj2(nothing(obj1) );
return 1;
}

when i compile and run this code i expect to see :

default    // default constructor

copy       // returning from the function

move       // moving to the obj2

but when the code is getting execute it just show :

default 

copy

the compiler is Visual C++ 2015

mehdi
  • 1
  • 2

1 Answers1

0

Move signatures are supposed to be defined as T&&, not T const &&. While there's nothing in the language stopping you from declaring something T const &&, it makes no sense in practical terms: you mean to move from this object, but it's const and therefore can't have its state changed? It's a contradiction of terms.

Xirema
  • 19,889
  • 4
  • 32
  • 68