implicit constructor

Discussion in 'C++' started by Rahul, Oct 30, 2007.

  1. Rahul

    Rahul Guest

    Hi Everyone,

    I know that implicit conversion is invoked for the following case,

    class A
    {
    public: A(int n)
    {
    ...
    }
    };


    A obj = 2;

    But is any temp objects created? Is the 2 used to create a temp
    object and then is the temp object assigned to the the actual object
    obj?

    Thanks in advance!!!
    Rahul, Oct 30, 2007
    #1
    1. Advertising

  2. Rahul wrote:
    > Hi Everyone,
    >
    > I know that implicit conversion is invoked for the following case,
    >
    > class A
    > {
    > public: A(int n)
    > {
    > ...
    > }
    > };
    >
    >
    > A obj = 2;
    >
    > But is any temp objects created? Is the 2 used to create a temp
    > object and then is the temp object assigned to the the actual object
    > obj?


    The semantics are such that a temporary object is created. However,
    the Standard allows the compiler to forgo creation of a temporary in
    such case and construct 'obj' as if you wrote

    A obj(2);

    The copy-constructor in 'A' has to still be accessible, though.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Oct 30, 2007
    #2
    1. Advertising

  3. Rahul

    Rolf Magnus Guest

    Rahul wrote:

    > Hi Everyone,
    >
    > I know that implicit conversion is invoked for the following case,
    >
    > class A
    > {
    > public: A(int n)
    > {
    > ...
    > }
    > };
    >
    >
    > A obj = 2;
    >
    > But is any temp objects created? Is the 2 used to create a temp
    > object and then is the temp object assigned to the the actual object
    > obj?


    It's not assigned, but rather copy-constructed. Apart from that, see
    Victor's answer.
    Rolf Magnus, Oct 30, 2007
    #3
  4. Rahul

    cplusplus Guest

    Hey Rahul tell me you little bitch why won't you get laid . Dude if
    girls don't want to **** you become a faggot . If guys don't want to
    **** you go rent a hooker . If no hooker will **** you go to a maximum
    security prison and become somebodies assfucking , ball sucking
    bitch . If that doesn't happen either ,then dude you are a serius
    loser .
    cplusplus, Oct 30, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sb
    Replies:
    10
    Views:
    4,607
    Andre Heinen
    Feb 25, 2004
  2. flopbucket
    Replies:
    1
    Views:
    495
    Tom Widmer
    Jun 26, 2006
  3. Alex Vinokur
    Replies:
    9
    Views:
    410
    Thomas J. Gritzan
    Aug 10, 2006
  4. Jess
    Replies:
    3
    Views:
    298
    Robert Bauck Hamar
    Jun 14, 2007
  5. Generic Usenet Account
    Replies:
    10
    Views:
    2,218
Loading...

Share This Page