سؤال

In C++11 standard (clause 3.3.9/3) i found this code snippet:

template<class T, T* p, class U = T> class X { /∗ ... ∗/ };

Can anybody explain for me which possible (and usefull) code can contain in body of class X? With usage of parameter p ofcourse.

هل كانت مفيدة؟

المحلول

If foo is a global object of type T, you can pass a pointer-to-foo to the template class X.

As an example, suppose T was an ostream. I can create two logging types, which based on the type output to error or out. Their static methods can even do it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top