c++ - Confused between a copy constructor and a converting constructor -


since have doubts question (for c++03) posting here.i read conversion constructors , states

"to converting constructor, constructor must have single argument , declared without keyword explicit."

now question whether copy constructor can called conversion constructor provided not explicitly declared ? qualify 1 ? believe cant called conversion constructor because accepts same type parameter ths resulting in no conversion. instance

foo a; foo b; = 100; //a conversion constructor called (i.e) foo(int a){...} = b ;  //since both objects same type , have been initialized assignment operator called (if there overloaded version otherwise default called) 

is understanding correct ?

quoting standard:

[class.conv.ctor]/3

a non-explicit copy-constructor (12.8) converting constructor. implicitly-declared copy constructor not explicit constructor; may called implicit type conversions.

so yes, copy-ctor converting ctor.

also note [conv]/1 specifies , points out in remark:

note: standard conversion sequence can empty, i.e., can consist of no conversions.

and in /3:

an expression e can implicitly converted type t if , if declaration t t=e; well-formed

so set of implicit conversions contain empty conversions.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -