Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Promiscuous Robot

virtual static members.

This topic is 6373 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
quote:
Original post by Promiscuous Robot
Basically I am just wondering if its possible, and if it''s something to be avoided, or has issues, or something.



Not possible. static methods run at class-level, while virtual methods run at object-level.



---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!

Share this post


Link to post
Share on other sites
The easiest way to tell if it is possible is to try it and see if the compiler accepts it. I don''t see any technical reason why you couldn''t have virtual static methods. The same arguement presented would be just as valid for arguing you couldn''t have static methods at all. The only issue that really matters though is whether the compiler will flag it as an error or not.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Is this C++ you''re talking about? If so "virtual static" doesn''t even make sense. static members have no object associated with them - they''re basically no different than a regular (non-member) function except that they''re in a different namespace. "virtual" is inherently concerned with the object heirarchy. No object, no virtual.

What are you *really* trying to do that you think you need "virtual static"?

-Mike

Share this post


Link to post
Share on other sites
i agree w/ lilbuddywizer, because what to say that you can't override a static function in a derived class?

I think it's perfectly legal, and u know what?

*adds virtual to a static member*
*hits compile*

well, msvc++ doesn't allow it, but hey, msvc isn't ansi.


Compiler Error C2576
'identifier' : virtual used for static member function


A static member function was declared as virtual.

The virtual function mechanism relies on the specific object that calls the function to determine which virtual function is used. Since this is not possible for static functions, they cannot be declared as virtual.


oh well...



Edited by - Succinct on February 1, 2001 6:12:08 PM

Share this post


Link to post
Share on other sites
Think about it.
A virtual static is an oxymoron.

You /can/ override static methods, but they cannot be called from a base class pointer. Static methods are not _thiscall's, so they don't get a vtable, so they can't be virtual because there's no way to resolve a virtual call without a this pointer.

Remember, you can call a static methods just using the class name, you don't need any pointer at all.

If you can determin which static method to use without using the this pointer, then there's no reason to make it virtual.
QED

Edited by - Magmai Kai Holmlor on February 1, 2001 6:25:50 PM

Share this post


Link to post
Share on other sites
Hmm.. yes yes I realize the stupidity of the request.. But I asked because it would''ve made my life easier..

Oddly enough I don''t even remember why I wanted one because I guess I designed around it...

oh well.

Share this post


Link to post
Share on other sites
quote:
Original post by Succinct
i agree w/ lilbuddywizer, because what to say that you can''t override a static function in a derived class?

I think it''s perfectly legal, and u know what?



Yup, you''re wrong. The ANSI C++ Standard and the nature of the qualifiers ''static'' and ''virtual'' dictate that they cannot be used together.

Depending on your compiler to define what is legal will cause no end of problems when you try to port your software, use another compiler, or the compiler changes (and yes, the latter happens regularly).


---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!