If we have
class A {
private:
public:
A(int a, int b) {std::cout << "You passed two numbers!;}
};
and I wish to create another constructor where the value of a
is assumed 0 and we pass the value of b
, will these two produce the same result:
// First variant
A(int b) : A(0, b) {}
// Second variant
A(int b) {A(0, b);}
I'm asking since in one of my codes I have
A(int minPrice, int maxPrice) {
if (minPrice < 0 || maxPrice < 0)
throw std::range_error("Illegal price");
A::minPrice = minPrice;
A::maxPrice = maxPrice;
}
and this produces an issue when I use the second variant; namely, when I call A(0, maxPrice)
from inside that new one-parameter constructor.