【初心者歓迎】C/C++室 Ver.50【環境依存OK】at TECH
【初心者歓迎】C/C++室 Ver.50【環境依存OK】 - 暇つぶし2ch98:デフォルトの名無しさん
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]; の行です。
どうかもうすこし教えてください。




次ページ
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch