Thread: Help me understand copying better

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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;
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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,318
    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
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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
    Location
    Inside my computer
    Posts
    24,654
    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.

Popular pages Recent additions subscribe to a feed