samedi 23 avril 2016

How come there's no 'this_class' - the static equivalent of 'this'?

When you're in a C++ non-static method, you can use the this variable to refer to the current instance; and through the instance you also have the type. In static methods, I would expect to have something like a this_class type available to me, which is the type of the class in which I'm implementing the method. Even if it's not inherited (i.e. for class B : public A, method A::foo() will have this_class being A even when accessed through B) - it would still be useful, for example when you're implementing a static method in a class with many template arguments, and you want to call some out-of-class function templated on your class's type.

So, was this possibility ever considered? Are there reasons it would complicate things for the developer or the compiler?





Aucun commentaire:

Enregistrer un commentaire