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.

链接地址: http://www.djcxy.com/p/96362.html

上一篇: 在C ++中,对C API回调使用静态成员函数指针是否安全/可移植?

下一篇: 声明一个静态成员函数const或virtual