Gary Labowitz said:
Is it permissable to place default arguments in the definition of a
constructor rather than in the declaration.
Yes, but it's rather useless, don't you think? The whole
idea to have default argument values in the declaration is
to let compiler use them. If you stuff the default values
in the definition (which should be in a separate module,
I suppose), the compiler will not see them.
If your definition right here, in the same unit as the class
definition with the constructor declaration, then the default
values should be picked up, since the definition is itself
a declaration, and default values are allowed to be added in
consecutive declarations of the same function.
Following extract:
class X
{
public:
X(int arg1, int arg2);
...
}
X::X(int arg1=7, int arg2=9)
{
...
}
compiles using Dev-C++ (mingw); fails using VC++.
Which compiler is right?
Neither. The code in the presented form is not compilable.
But if you write a compilable example:
struct A
{
A(int a);
};
A::A(int a = 10)
{
}
int main()
{
A a;
}
VC++ fails _incorrectly_. Intel C++, Comeau C++, also compile
this example without a hitch. I didn't check GCC.
Victor