By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,084 Members | 1,969 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,084 IT Pros & Developers. It's quick & easy.

why static function can not be virtual

P: 4
Why we can not declared a static function as virtual function.
Jun 14 '07 #1
Share this Question
Share on Google+
4 Replies


Savage
Expert 100+
P: 1,764
Why we can not declared a static function as virtual function.
Virtual functions are used mostly to achieve dynamicly binding or runtime polymorphism.

Now can you tell me for what are static functions used?


I'm sure that you will figure it out...

Savage
Jun 14 '07 #2

DeMan
100+
P: 1,806
A static function is used to edit variables that are not specific to a particular instance of a class. For example, if we have a "student" class, we might use a static method to increment the number of times a "student" instance is created.

A virtual function, is a function that can be overridden by a sub-class. That is if we have a cirtual "compare" function for some class "person", and we have a class "student" extending "person", we can overwrite the virtual "compare" function to compare students slightly differently to how people are compared....

This means that it wouldn't make sense to have a static virtual (or virtual static) method/function. If the class "person" had the counter method described for student (above), and allowed the student class to override it, it could become virtually impossible (no pun intended) to determine which method to call (or even which variables to update), when different "person" or "student" entities are called.
Jun 14 '07 #3

DeMan
100+
P: 1,806
sorry Savage,
I was halfway through - didn't realise you had posted already......
Jun 14 '07 #4

Savage
Expert 100+
P: 1,764
sorry Savage,
I was halfway through - didn't realise you had posted already......
No problem..

Savage
Jun 14 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.