-1

I have a template class with a static method, ideally I would like to add to this method something like this std::cout << decltype(this) << std::endl; but this doesn't compile since I can not use this inside a static method. I found a working example here (not sure I can print decltype output) but it also uses this so I can not use it inside the static method. I was forced to use it inside the constructor, but I didn't give up yet. Does anyone has an idea how to print the class type inside a static method?

Community
  • 1
  • 1
e271p314
  • 3,841
  • 7
  • 36
  • 61

1 Answers1

3

Did you mean something like:

#include <iostream>
#include <typeinfo>

template <typename T>
class C
{
public:
    static void print()
    {
        std::cout << typeid(C).name() << std::endl;
    }

};

int main() {
    C<int>::print();
    C<char>::print();
    return 0;
}
Jarod42
  • 203,559
  • 14
  • 181
  • 302