implicit constructor

R

Rahul

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!!!
 
V

Victor Bazarov

Rahul said:
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
 
R

Rolf Magnus

Rahul said:
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.
 
C

cplusplus

Hey Rahul tell me you little bitch why won't you get laid . Dude if
girls don't want to **** you become a ****** . 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 .
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top