Thread: move semantics / rvalue references

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838

    move semantics / rvalue references

    just now looking into this. not sure if i'm doign it wrong. a sanity check would be much appreciated.

    Code:
    Matrix&& Matrix::operator +(const Matrix& b)const
    {
        Matrix result(*this);
        result+=b;
        return (Matrix&&)result;
    }
    
    Matrix::Matrix(Matrix&& rhs):
       data(rhs.data),
       rows(rhs.rows),
       cols(rhs.cols)
    {
    }
    
    void foo()
    {
       Matrix a;
       Matrix b;
       Matrix aPlusB(a+b);
    }
    edit: ok it seems like i am definitely missing the point. this is the usage case i'd like to accomodate: using arithmetic operators on matrix operations without any extraneous copies. if someone can assist in disabusing me of my ignorance that would be fantastic.

    thanks.
    Last edited by m37h0d; 12-08-2011 at 09:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rvalue references and move semantics in C++11
    By webmaster in forum C++ Programming
    Replies: 14
    Last Post: 11-17-2011, 04:01 AM
  2. Returning a rvalue from function
    By Memloop in forum C++ Programming
    Replies: 11
    Last Post: 09-22-2009, 02:47 PM
  3. lvalue rvalue discussion
    By George2 in forum C++ Programming
    Replies: 18
    Last Post: 03-04-2008, 05:48 AM
  4. Get lvalue through rvalue
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 12-17-2007, 08:53 AM
  5. declare references to references works!
    By ManuelH in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2003, 08:14 AM