【初心者歓迎】C/C++室 Ver.50【環境依存OK】 at TECH
[2ch|▼Menu]
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