D
Dumitru Sipos
Hello everybody!
is there possible to have a function that is both static and virtual?
Dumi.
is there possible to have a function that is both static and virtual?
Dumi.
Dumitru said:Hello everybody!
is there possible to have a function that is both static and virtual?
Dumitru Sipos said:Hello everybody!
is there possible to have a function that is both static and virtual?
Mike said: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.
Sjoerd said: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.
Sjoerd A. Schreuder said: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.
Rolf said:Huh? Of course it depends on the this-pointer.
... of the object. But with a static function, you don't have an object.
What would be the sense of the above? You would call the function e.g. as:
std::string author = Baseobject::getCodeAuthor();
Now which one should that call be dispatched to, and why?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.