Richard Gillilan wrote:
>
8<
>
> > 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?
In fact I meant:
class B : public A {
virtual int methodA (void);
int methodB (void);
};
or (as virtualness is being inherited)
class B : public A {
int methodA (void);
int methodB (void);
};
In fact I your corrected version is something quite tricky and I not
sure just what the compiler would make from it.
C++ indeed isn't to confusing. Still there are a lot little details
which come into play once you dig deeper and which can take you by
suprise (even though they quite logical in the end).
> 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! ;)