Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Static and ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 9815 of 9909
Post > Topic >>

Re: Static and virtual

by Alberto Ganesh Barbati <AlbertoBarbati@[EMAIL PROTECTED] > Jul 22, 2008 at 12:12 AM

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! ]
 




 3 Posts in Topic:
Static and virtual
rkldabs@[EMAIL PROTECTED]  2008-07-21 14:33:50 
Re: Static and virtual
Alberto Ganesh Barbati &l  2008-07-22 00:12:37 
Re: Static and virtual
amirkam1@[EMAIL PROTECTED  2008-07-22 15:58:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 20 4:35:29 CDT 2008.