de**********@hotmail.com wrote:
When writing the following code:
class Base
{
Base(const Base &rhs) {}
~Base();
};
void f() {
Base b;
};
The compiler shouts: no appropriate default constructor available
But when changing it to:
void f() {
Base b();
};
it compiles. Why?
The compiler is correct. A default constructor either takes no
parameters or has default values for all of the parameters, hence
enabling the default constructor call with no parameters or using the
already defined default parameters. Hence any one of the following is a
valid default constructor:
Base() { .... }
Base(int n = 7) { .... }
Base(char *name = NULL, unsigned id = 0) { .... }
JB