fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template< typename T > class buffer
  5. {
  6. public:
  7. T * data;
  8. buffer(){data = new T[10];}
  9. const T & operator [] ( size_t ) const;
  10. T & operator [] ( size_t );
  11.  
  12. operator const T * () const;
  13. operator T * ();
  14. };
  15.  
  16. int main() {
  17. buffer< int > buf;
  18. buf[ 0 ]; // Generates an error
  19. return 0;
  20. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:18:12: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
     buf[ 0 ]; // Generates an error
            ^
prog.cpp:10:15: note: candidate 1: T& buffer<T>::operator[](size_t) [with T = int; size_t = unsigned int]
           T & operator [] ( size_t );
               ^
prog.cpp:18:12: note: candidate 2: operator[](int*, int) <built-in>
     buf[ 0 ]; // Generates an error
            ^
prog.cpp:18:12: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
prog.cpp:10:15: note: candidate 1: T& buffer<T>::operator[](size_t) [with T = int; size_t = unsigned int]
           T & operator [] ( size_t );
               ^
prog.cpp:18:12: note: candidate 2: operator[](const int*, int) <built-in>
     buf[ 0 ]; // Generates an error
            ^
/home/ntCEfH/cc1Sg4bI.o: In function `main':
prog.cpp:(.text.startup+0x24): undefined reference to `buffer<int>::operator[](unsigned int)'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty