Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

named entity as pointer to T in template parameter list [closed]

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.

like image 590
αλεχολυτ Avatar asked Nov 01 '22 02:11

αλεχολυτ


1 Answers

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.

like image 70
Yakk - Adam Nevraumont Avatar answered Nov 09 '22 23:11

Yakk - Adam Nevraumont