Files
linux-kernel-module-cheat/userland/cpp/template_class_with_static_member.cpp
Ciro Santilli 六四事件 法轮功 ab5ff0c28b sfinae hello world
2020-10-20 03:00:02 +00:00

21 lines
314 B
C++

// https://cirosantilli.com/linux-kernel-module-cheat#cpp-templates
#include <cassert>
template <class T>
struct MyClass {
static int i;
MyClass() {
i++;
}
};
template <class T>
int MyClass<T>::i = 0;
int main() {
MyClass<int>();
MyClass<int>();
assert(MyClass<int>::i == 2);
}