> You must not specific default parameters anywhere except in the
> declaraction.
> The reasons are simple: First the default parameters are substitued by
> the compiler, hence it must be able to see them. Second, on a less
> technical side, you expect the Object(-method) to behave as advertised
> in the declaration. Implementations are regarded as invisible in OO.
> Changing the default parameters (why else would you want to type them
> twice) would break this.
Yes, I can see now it wouldn't make sense to be able to override the function
declaration in a particular implementation, in fact, when I try to
compile
----------------------------------------
...
void test(float, int = 10);
void test(float x, int y = 10) { ... }
...
----------------------------------------
the SGI compiler tells me:
-----------------------------------------------
> CC test.C
cc-1281 CC: ERROR File = test.C, Line = 5
There is a redefinition of a default argument.
void test(float x, int y = 10) {
^
1 error detected in the compilation of "test.C".
------------------------------------------------
> Declaring a method virtual is not identical to being able to override
> its implementation. Any method can be overriden. However the main
> difference is what method is being called when you hold only a reference
> to a base type. Look at this:
>
> class A{
> virtual int methodA (void);
> int methodB (void);
> };
>
> class B{
> virtual int methodA (void);
> int methodB (void);
> };
you must mean
class B:A {
virtual int methodA (void);
virtual int methodB (void);
};
so B inherits from the base class A, correct?
So, to be more specific, I should say that "virtual" allows derived classes
to override same-name methods in the parent "base" class when passed in
to functions as a reference to an object of type "base class".
Thanks for the clarification.
Richard
ps, C++ isn't that confusing, really! ;)