1

Out of curiosity, is it possible to get the type of the current class without spelling out its name in a static context?

The idea was something like this:

class Foo{
    auto clone () -> decltype(*this);
}

But this does only work in non-static contexts. Member declarations like these are not possible:

class Foo{
    static auto make() -> decltype(*this); //"this" is not valid in a static function
    decltype(*this) secondFoo;
    static decltype(*this) instance;
}

So, is there something I can replace decltype(*this) with that would make the above declarations valid?


A workaround is of course to typedef Foo OwnType; and then use OwnType, I'm just curious if there are also different ways.


I would like to do that for a PMP function that defines a load of static member variables that are of the same type as the class the function is called in.

iFreilicht
  • 13,271
  • 9
  • 43
  • 74

0 Answers0