- 98 名前:デフォルトの名無しさん [2008/03/16(日) 00:26:29 ]
- >>92-97
ありがとうございます。 アドバイスを総合して実装してみたのですが、コンパイルが通りません。 #include <iostream> #include <vector> using namespace std; template <typename T> class cvector : public std::vector<T> { T operator[](const int n) const { int index = (n >= 0) ? n : this->size()-n; // assert(n >= 0); return (*this)[index % this->size()]; } }; int main(){ cvector<int> vec; vec.push_back(11); cout << vec[0]; return 0; } コンパイルエラーはこうです。 test.cpp:6: error: 'T cvector<T>::operator[](int) const [with T = int]' is private//T operator[](const int n) const {の行です。 test.cpp:15: error: within this context // cout << vec[0]; の行です。 どうかもうすこし教えてください。
|

|