Assigning an object variable to a constant reference

This is a discussion on Assigning an object variable to a constant reference within the C++ Programming forums, part of the General Programming Boards category; It applies when you want to construct temporaries in the argument list, and these temporaries take one argument, where you ...

  1. #16
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It applies when you want to construct temporaries in the argument list, and these temporaries take one argument, where you pass a single identifier, or no argument. Then it is interpreted as a function taking arguments of the types of the temporaries, those arguments either unnamed or with the name you specified.

    Wow, those are illegible sentences.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #17
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186
    for performance sake, dont return user-defined types by value. Instead make a free-operator function that takes three arguments like so
    Code:
    void func(Obj& returnValue, const Obj& obj1, const Obj& obj2);
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Bah.

    First, prove to me that the return-by-value is an actual performance problem. Then you may introduce the uglification of the interface.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,010
    I concur with CornedBee. Many times the performance hit is negligible. And other times, it is even optimized away.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Using Vectors. MinGW warning
    By Viewer in forum C++ Programming
    Replies: 9
    Last Post: 03-26-2009, 04:15 PM
  3. Managing a reference object
    By Mario F. in forum C++ Programming
    Replies: 4
    Last Post: 11-23-2006, 07:41 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 10:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21