Thread: Gcc can't find obvious copy constructor

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I'm not sure I follow the logic behind the const requirement.
    The requirement has nothing to do with performance or strict correctness. The fact is that non-const reference parameters should only be used where there is the intention of modifying the argument. With a temporary, such modifications would not be visible when the function returns. Thus, passing a temporary to a function expecting a non-const reference is most likely unintentional and the wrong thing to do. The C++ standard committee thought this sufficient reason to forbid binding non-const references to temporaries. MS thought differently, and later got caught in compatibility concerns.
    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. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    141
    Quote Originally Posted by CornedBee View Post
    The requirement has nothing to do with performance or strict correctness. The fact is that non-const reference parameters should only be used where there is the intention of modifying the argument. With a temporary, such modifications would not be visible when the function returns. Thus, passing a temporary to a function expecting a non-const reference is most likely unintentional and the wrong thing to do. The C++ standard committee thought this sufficient reason to forbid binding non-const references to temporaries. MS thought differently, and later got caught in compatibility concerns.
    OK I can see the logic of that. My only problem is that when I adhere by this I seem to get a lot errors from MS Visual studio with regards to passing non constant parameters into the arguments. I end up doing const casts and the const keyword starts to spread like a virus.

    When I have time I'll try to generate a case of this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer conversion problems with a copy constructor
    By stanlvw in forum C++ Programming
    Replies: 8
    Last Post: 01-14-2008, 12:06 AM
  2. Copy constructor for Queue ADT (as an Array)
    By clegs in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2007, 11:05 PM
  3. Replies: 2
    Last Post: 04-04-2007, 06:34 PM
  4. Can't find my constructor
    By Nippashish in forum C++ Programming
    Replies: 4
    Last Post: 12-06-2002, 08:17 PM
  5. copy constructor
    By Eber Kain in forum C++ Programming
    Replies: 1
    Last Post: 09-30-2002, 05:03 PM