mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
c++: template class with static member
This commit is contained in:
20
userland/cpp/template_class_with_static_member.cpp
Normal file
20
userland/cpp/template_class_with_static_member.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// https://cirosantilli.com/linux-kernel-module-cheat#cpp
|
||||
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user