rkldabs@[EMAIL PROTECTED]
ha scritto:
> Hi,
>
> Consider the code shown below which is well-formed. However if I make
> the base class version as virtual and try to make the derived class
> version as static, the code is ill-formed i.e gcc gives error.
>
> struct A{
> static void fn(){} // make this as virtual
> };
>
> struct B : A{
> virtual void fn(){} // make this as static
> };
>
> int main(){
> B b;
> b.fn();
> }
>
> Which ****tion of the C++ standard talks about
>
> a) the above code 'as is' being well-formed and
I don't think there's a ****tion of the standard explicitly allowing
this, but I'm sure that it's not disallowed, so... it's allowed because
it's not disallowed (that's how the standard works, sorry) The
definition of fn in B simply hides the definition in A.
> b) the above code modified as per the comments inline being ill-
> formed.
This is because 10.3/2 requires that B::fn shall be virtual. As it
cannot be both virtual and static, the code is ill-formed (9.4.1/2).
> All I could gather was the mention in the standard about the
> overloading aspect with static and virtual functions with the same
> name
>
> $13.1- "Member function declarations with the same name and the same
> parameter-type-list cannot be overloaded if any of them is a static
> member function declaration (9.4)."
>
Overloading does not occur here, so this reference is irrelevant.
HTH,
Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|