【初心者歓迎】C/C++室 Ver.50【環境依存OK】
at TECH
98:デフォルトの名無しさん
08/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]; の行です。
どうかもうすこし教えてください。
次ページ続きを表示1を表示最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
4863日前に更新/60 KB
担当:undef