I am trying to understand conversion constructors. I am using the following piece of code
class cls
{
public:
cls()
{
std::cout << "Regular constructor \n"; ---> Line A
}
cls (int a) //Constructing converter
{
std::cout << "Int constructor \n"; ---> Line B
}
cls (cls& d) //Copy constructor
{
std::cout << "Copy constructor \n"; ---> Line C
}
};
int main()
{
cls d;
std::cout << "-----------------------\n";
cls e = 15; //int constructor then copy constructor
return;
}
Now I am confused at the statement cls e = 15
my understanding was that this statement was suppose to call Line B(Conversion Cont) and then Line C (Copy constructor) however it only called Line B. I though cls e = 15
was equivalent to cls e = cls(15)
. So I tried cls e = cls(15)
which also only gives the Line B. I would appreciate it if someone could explain what happens when we use the following
cls e = cls(15)
//I was expecting a conversion constructor followed by copy constructor but apparently i was wrong. Any explanation on what is happening would be appreciated