Mike Wahler wrote:
"Dumitru Sipos" <du***********@gmail.com> wrote in message
news:1104930790.279965@slbhw0...
is there possible to have a function that is both static and virtual?
If you study the language definitions of what static member functions
and virtual member functions are, you should realize your question
does not make much sense.
It can make sense! RTTI typically doesn't depend on the this-pointer
(static) while RTTI typically depends on the dynamic type (virtual).
class Baseobject
{
virtual static std::string getCodeAuthor() = 0;
}
class A : BaseObject
{
virtual static std::string getCodeAuthor() { return "Sjoerd"; }
}
class B : BaseObject
{
virtual static std::string getCodeAuthor() { return "Mike"; }
}
Maybe there are reasons why "static virtuals" should not be allowed,
but "it doesn't make sense" is certainly not one of them.
Note: I'm quite aware of the fact that C++ doesn't allow
static virtuals, and of the fact that there is an easy work-around
by using regular virtual functions.
Sjoerd