Richard Gillilan wrote:
>
> Rick Scott wrote:
> >
> > Where did you get that line???? From line 88 in src/uipp/base/DropSite.C I
> > have
> >
> > void DropSite::setDropWidget(Widget drop_w, unsigned char type,
> > Pixmap animation, Pixmap animation_mask)
> >
>
> The function prototype for setDropWidget in class DropSite is in DropSite.h at
> line 69. It's declared virtual, which, if I remember correctly, means that
> it can be overidden in derived classes. It is strange that
> the actual function definition in DropSite.C does not also specify the
> defaults, but it may still be legal. I seem to remember a warning
> somewhere in the netscape programmer's portability guide about
> something like this. I'll try to dig it up.
>
> Richard
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.
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);
};
void some_sort_of_function_or_method(A & a_class_reference);
int main(int argc, char *argv[]){
B b_class;
some_sort_of_function_or_method(b_class);
return 0;
}
void some_sort_of_function_or_method(A & a_class_reference) {
int i;
i = a_class_a_reference.methodA(); // calls methodB of class B
i += a_class_a_reference.methodB(); // calls methodB of class A
}
Hope that helped a bit,
Jan