C++ (Qt)#include <cstdio> template<int N> class Tmpl { private : void _f() { printf("Template. %d\n", N); } public : void f() { _f(); printf("%d\n", N); }}; class Instance : public Tmpl<1> { private : void _f() { printf("Instance.\n"); }}; int main() { Instance* instance = new Instance(); instance->f(); delete instance; return 0;}
DOSTemplate. 11
C++ (Qt)#include <cstdio>#include <cassert> template<int N, class Derived> class Tmpl { private : void _f() { printf("Template. %d\n", N); } public : void f() { static_cast<Derived*>(this)->_f(); printf("%d\n", N); }}; class Instance : public Tmpl<1, Instance> { friend class Tmpl<1, Instance>; public : void _f() { printf("Instance.\n"); }}; int main() { Instance* instance = new Instance(); instance->f(); delete instance; return 0;}
#include <cstdio> template<class T, int N> struct Tmpl { void f() { static_cast<T*>(this)->_f(); printf("%d\n", N); }}; struct Instance : Tmpl<Instance, 1> { void _f() { printf("Instance.\n"); }}; int main() { Instance* instance = new Instance(); instance->f(); delete instance; return 0;}
C++ (Qt)friend class Tmpl;
C++ (Qt)friend class Tmpl<1, Instance>;