I have written a test program:
#include <iostream>
class base
{
public:
base()
{
std::cout << "base 1" << std::endl;
}
base(int a)
{
std::cout << "base a=" << a << std::endl;
}
};
class child : public base
{
public:
child()
{
std::cout << "child" << std::endl;
}
};
int main(int argc, char* argv[])
{
child c;
return 0;
}
The program outputs the following:
$ ./a.out
base 1
child
Is there any possible way to send an integer argument to the base class thus calling the other form of the base constructor?
In the case that base has only one constructor I get a compile error: candidate expects 1 argument, 0 provided
, as you might expect. But if I give a default argument to that constructor, like:
base(int a = 10)
then my program compiles and runs, with the output: base a=10
. (Interesting?)
Is there any way to pass in a variable value of a
?