Declaring a static member function const or virtual
Why can't static member function be declared const?
I know a static function doesn't act on any particular instance of class. This means such function has no this pointer (passed implicitly as hidden argument) to any particular instance. But i don't understand why there is a compiler error when it is declared const, since it is not changing any particular instance.
Secondly, why can't static member function be declared virtual?
Need some clarification on this.
why there is a compiler error when it is declared const
const
means " this
is a pointer to a const
object". Since there's no this
, there's nothing for const
to modify.
why can't static member function be declared virtual
virtual
means "select the right function based on the actual dynamic type of this
". Since there's no this
, there's nothing to base the selection on.