Guest User

Untitled

a guest
Jul 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. template<typename T>
  2. class Test {
  3. public:
  4. T &operator[] (size_t i) {
  5. return t;
  6. }
  7. T t;
  8. };
  9.  
  10. void foo() {
  11. Test<int> t;
  12. t[2];
  13. }
  14.  
  15. ==========
  16.  
  17. $ gcc error.cpp
  18. error.cpp:6: error: declaration of ‘operator[]’ as non-function
  19. error.cpp:6: error: expected ‘;’ before ‘(’ token
  20. error.cpp:9: error: expected ‘;’ before ‘T’
  21. error.cpp: In function ‘void foo()’:
  22. error.cpp:14: error: no match for ‘operator[]’ in ‘t[2]’
  23.  
  24. $ clang error.cpp
  25. error.cpp:6:18: error: unknown type name 'size_t'
  26. T &operator[] (size_t i) {
  27. ^
  28. 1 diagnostic generated.
Add Comment
Please, Sign In to add comment