diff --git a/README.adoc b/README.adoc index 5110641..d89df7f 100644 --- a/README.adoc +++ b/README.adoc @@ -12982,6 +12982,8 @@ Programs under link:userland/cpp/[] are examples of https://en.wikipedia.org/wik * link:userland/cpp/empty.cpp[] * link:userland/cpp/hello.cpp[] +* templates +** link:userland/cpp/template.cpp[] [[cpp-multithreading]] ==== C++ multithreading diff --git a/userland/cpp/template.cpp b/userland/cpp/template.cpp new file mode 100644 index 0000000..7f7c038 --- /dev/null +++ b/userland/cpp/template.cpp @@ -0,0 +1,17 @@ +// https://cirosantilli.com/linux-kernel-module-cheat#cpp + +#include + +template +struct MyClass { + T myVal; + MyClass(T myVal) : myVal(myVal) {} + T myFunc() { + return myVal + 1; + } +}; + +int main() { + assert(MyClass(1).myFunc() == 2); + assert(MyClass(1.5).myFunc() == 2.5); +}