Say i have the following class :
class A
{
public:
A() {
}
A(int a):_a(a){
}
int _a;
};
And the following function :
void someFunc (A a)
{
cout << a._a;
}
So the following line in the program works fine :
someFunc (5); // Calls A(int a) Constructor.
But the following does not :
someFunc(); //Compile error
One can expect that if it can build A when getting an integer,
why not build one using the default constructor as well, when called with no arguments?
This is because the signature of
someFunc()does not match that ofvoid someFunc (A a).According to C++ standard, Section 13.3.2.3:
None of this applies in this case, so
void someFunc (A a)is not considered viable for the invocation with an empty parameter list.