Guest User

http://stackoverflow.com/questions/8430906/constructor-templ

a guest
Dec 8th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. enum obj_type{obj1,obj2};
  6.  
  7. template<int N>
  8. struct obj
  9. {
  10. };
  11.  
  12.  
  13.  
  14. template <class T>
  15. class A
  16. {
  17.     public:
  18. A(int, int);
  19.     private:
  20.             int a_;
  21.         int b_;
  22.         obj_type type;
  23. };
  24.  
  25.  
  26. template<>
  27. A<obj<obj1> >::A(int a, int b):a_(a),b_(b)
  28. {
  29. cout<<"case 1"<<endl;
  30. this->type=obj1;
  31. }
  32.  
  33.  
  34. template<>
  35. A<obj<obj2> >::A(int a, int b):a_(a)
  36. {
  37. b_=0;
  38. cout<<"case 2"<<endl;
  39. this->type=obj2;
  40. }
  41.  
  42.  
  43.  
  44. int main()
  45. {
  46.  
  47.     A<obj<obj2> > a(1,2);
  48. return 1;
  49. }
  50.  
  51.  
Add Comment
Please, Sign In to add comment