Template partial specialization


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #include <iostream>
  2. #include <string>
  3.  
  4. template< class T >
  5. class Foo;
  6.  
  7. template< class T>
  8. class Foo< T* > {
  9. public:
  10. Foo( const T *t ):
  11. t_( t ) {}
  12. void print() const {
  13. std::cout << *t_ << std::endl;
  14. }
  15. private:
  16. const T *t_;
  17. };
  18.  
  19. int main() {
  20. std::string s( "42" );
  21. Foo< std::string* >( &s ).print();
  22. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.