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

18 lines
337 B
C++

// https://cirosantilli.com/linux-kernel-module-cheat#cpp-templates
#include <cassert>
template <class T>
struct MyClass {
T myVal;
MyClass(T myVal) : myVal(myVal) {}
T myFunc() {
return myVal + 1;
}
};
int main() {
assert(MyClass<int>(1).myFunc() == 2);
assert(MyClass<float>(1.5).myFunc() == 2.5);
}