The Example class is shown below:
class Example
{
public:
Example(): x_(0) {} // problematic constructor
Example(int x = 1): x_(x){} // not problematic constructor
int getX() { return x_; }
private:
int x_;
};
Testing out Example in main:
int main()
{
// problem with this constructor
Example example1;
auto x1 = example1.getX();
// no problem with this constructor
Example example2(500);
auto x2 = example2.getX();
}
Issue Solved:
Eliminate constructor ambiguity by removing the default parameter values in the 2nd constructor. The constructors would look as follows:
Example(): x_(0) {}
Example(int x): x_(x){}
This would not violate the rules of cpp constructor overloading that lead to ambiguity.