flyrev@flyrev-VirtualBox:~/Desktop$ cat test.cpp
#include <vector>
template <class T>
class wrapped_vector {
private:
std::vector<T> elements;
public:
wrapped_vector() {
elements.resize(20);
}
typename std::vector<T>::reference operator[](typename std::vector<T>::size_type i) {
return elements[i];
}
typename std::vector<T>::const_reference operator[](int i) const {
return elements[i];
}
};
int main(void) {
wrapped_vector<int> test_int;
test_int[0] = 1;
wrapped_vector<bool> test_bool;
test_bool[0] = true;
}
flyrev@flyrev-VirtualBox:~/Desktop$ g++ test.cpp
test.cpp: In function ‘int main()’:
test.cpp:23: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: [enabled by default]
test.cpp:16:43: note: candidate 1: typename std::vector<T>::const_reference wrapped_vector<T>::operator[](int) const [with T = int; typename std::vector<T>::const_reference = const int&]
test.cpp:12:37: note: candidate 2: typename std::vector<T>::reference wrapped_vector<T>::operator[](typename std::vector<T>::size_type) [with T = int; typename std::vector<T>::reference = int&; typename std::vector<T>::size_type = long unsigned int]
test.cpp:23:16: error: assignment of read-only location ‘test_int.wrapped_vector<T>::operator[]<int>(0)’
test.cpp:26:13: 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: [enabled by default]
test.cpp:16:43: note: candidate 1: typename std::vector<T>::const_reference wrapped_vector<T>::operator[](int) const [with T = bool; typename std::vector<T>::const_reference = bool]
test.cpp:12:37: note: candidate 2: typename std::vector<T>::reference wrapped_vector<T>::operator[](typename std::vector<T>::size_type) [with T = bool; typename std::vector<T>::reference = std::_Bit_reference; typename std::vector<T>::size_type = long unsigned int]
test.cpp:26:17: error: lvalue required as left operand of assignment
flyrev@flyrev-VirtualBox:~/Desktop$