Help me understand copying better

This is a discussion on Help me understand copying better within the C++ Programming forums, part of the General Programming Boards category; It doesn't. It uses a built-in assignment operator instead. No, it uses the compiler provided copy constructor. In that case ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,315
    It doesn't. It uses a built-in assignment operator instead.
    No, it uses the compiler provided copy constructor.

    In that case the compiler is allowed to also use the copy-constructor, instead of a call to the default constructor followed by a call to the assignment operator. So you can't actually say that it will call the assignment operator. It's compiler dependent.
    I do not have a copy of the C++ Standard with me at the moment, but I believe that it is not compiler dependent: this syntax means an implicit invocation of the copy constructor. If you declare the copy constructor explicit, then one must use:
    Code:
    SomeObject object2(object1);
    instead of:
    Code:
    SomeObject object2 = object1;
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    Quote Originally Posted by laserlight View Post
    No, it uses the compiler provided copy constructor.
    Gah, yes, I wrote the wrong thing >_<
    Stupid mistakes >_<

  3. #18
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by laserlight View Post
    I do not have a copy of the C++ Standard with me at the moment, but I believe that it is not compiler dependent: this syntax means an implicit invocation of the copy constructor.
    You could be right. I can't confirm it either.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #19
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by force of will View Post
    In VS 8 it prints "assign!", in gcc it prints nothing, so maybe compiler depend or non standard feature, although im more inclined to the second one
    Wow. I guess I'll never be using that compiler then, as that is absolutely, critically broken.

  5. #20
    Registered User
    Join Date
    Nov 2007
    Posts
    19
    Quote Originally Posted by brewbuck View Post
    Wow. I guess I'll never be using that compiler then, as that is absolutely, critically broken.
    My bad i just deleted that post, im guessing im seeing things lol :P

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    I can't find that VC++ calls the assignment operator instead of the copy constructor. The "print" test prints nothing, so there shouldn't be anything wrong with the compiler.

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

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