Posted By

mkluwe on 08/04/10


Tagged

template example partial specialization


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

khouser


Template partial specialization


 / Published in: C++
 

  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  

You need to login to post a comment.