Why can't static functions be virtual

Xinok xnknet at gmail.com
Tue Jan 16 21:19:16 PST 2007


Simply put, static functions don't have a 'this' pointer, so it's impossible to make a static function a virtual function.
Objects with virtual functions have a 'hidden ID' which sets a unique value for each class type (AFAIK anyways...). If you don't have the 'this' pointer, you can't read the hidden ID in the object, so you don't know what type the object is, making it impossible to know which virtual function to call.



More information about the Digitalmars-d mailing list