I have a class 'Entity'. It has a user-defined constructor (implicit) with one argument as shown below.
class Entity
{
public:
Entity(int a)
{
std::cout << a << std::endl;
}
Entity(const std::string& s)
{
std::cout << s << std::endl;
}
};
int main()
{
Entity e1 = (10, 20);
Entity e2 = (10, 20, 30);
Entity e3 = (10, 20, 30, 40);
Entity e4 = (std::string("Hello"), std::string("World"));
return 0;
}
The output of the above program is
20
30
40
World
Can anyone tell me why only the last value (integer, string) passed is printed?
Note: If the constructor is made explicit
, then there will be compilation error. Why this output with implicit
constructor?