Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. template <class T1>
  7. class A
  8. {
  9. static T1 x;
  10. static vector<T1> v;
  11.  
  12. public:
  13. static void testOne();
  14. };
  15.  
  16. template <class T1>
  17. T1 A<T1>::x = 56;
  18.  
  19. template <class T1>
  20. void
  21. A<T1>::testOne()
  22. {
  23.  
  24. A::x = 45;
  25. A::v.push_back(34);
  26.  
  27. cout << A::x << endl;
  28. cout << A::v.size() << endl;
  29. }
  30.  
  31. int
  32. main(int argc, char* argv[])
  33. {
  34. A<int>::testOne();
  35.  
  36. return 0;
  37. }
  38.  
  39. static.cpp:25:6: warning: instantiation of variable 'A<int>::v' required here,
  40. but no definition is available [-Wundefined-var-template]
  41. A::v.push_back(34);
  42. ^
  43. static.cpp:34:11: note: in instantiation of member function 'A<int>::testOne'
  44. requested here
  45. A<int>::testOne();
  46. ^
  47. static.cpp:10:21: note: forward declaration of template entity is here
  48. static vector<T1> v;
  49. ^
  50. 1 warning generated.
  51. Undefined symbols for architecture x86_64:
  52. "A<int>::v", referenced from:
  53. A<int>::testOne() in static-9790dc.o
  54. ld: symbol(s) not found for architecture x86_64
  55. clang: error: linker command failed with exit code 1 (use -v to see invocation)
  56.  
  57. static.cpp:18:8: error: use of undeclared identifier 'T1'
  58. vector<T1>A::v;
  59. ^
  60. static.cpp:18:11: error: 'A' is not a class, namespace, or enumeration
  61. vector<T1>A::v;
  62. ^
  63. static.cpp:7:7: note: 'A' declared here
  64. class A
  65. ^
  66. 2 errors generated.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement