main()
{
std::cout << makeNegative(7); // pass an integer value
return 0;
}
the class has such a default constructor
Drob(int numerator = 0, int denominator = 1) :
m_numerator(numerator), m_denominator(denominator)
{
assert(denominator != 0);
}
on one site it is written that since the call to the makeNegative() function expects an object of the Drob class, and we pass it a literal, an implicit conversion will occur
Drob d = 7
which is equal to
Drob d(7)
what the default constructor will call
and when the function reaches return, then the copy constructor will also work
Is everything right?
Sounds correct. Though having implicit constructors is usually not a good idea, especially from basic types. It can create some weird bugs and overall reduce readability (things happening, but the reader can't know from reading the code that they are happening).
Обсуждают сегодня