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?
Asked
Active
Viewed 666 times
-1
-
What is this even supposed to mean?! `decltype` denotes a *type*. What is `cout << int`? – Kerrek SB Jun 05 '14 at 09:26
1 Answers
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