Thread: Variable Reference Question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    Variable Reference Question

    Ok, I have this operator overloaded like this:

    Code:
    Vector3 operator + (Vector3& add);
    The code works fine but my question is, if I'm returning a non reference the overloaded operator will create a new Vector3 class and than return it. Now when it returns it, does it create a replica of the temp Vector3 class and than returns that? Here is the code for the overloaded operator:

    Code:
    Vector3 Vector3::operator + (Vector3 &add)
    {
    	return Vector3(x + add.x, y + add.y, z + add.z);
    }

    Also if I derefernece something like this: *this will it create a whole new variable of this? So if I have an operator that returns Vector& and I return the dereferenced of this, will it create a whole new this and than return a reference to it?
    Last edited by Rune Hunter; 04-01-2007 at 09:11 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Using Vectors. MinGW warning
    By Viewer in forum C++ Programming
    Replies: 9
    Last Post: 03-26-2009, 03:15 PM
  3. Call by reference question
    By badtwistofate in forum C Programming
    Replies: 4
    Last Post: 03-24-2009, 02:40 PM
  4. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM
  5. Passing the variable as a Reference
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 03-05-2002, 02:35 PM