STLリストを作成しています。MyList
特別なクラス ( ) のリストであるデコレータ クラス ( ) を作成しましたProtectMe
。リストのすべての項目を const にしたい。だからここに私が作ったものがあります:
#include <list>
using namespace std;
class ProtectMe{
private:
int data_;
public:
ProtectMe(int data):data_(data){
}
int data() const{return data_;}
};
class MyList{
private:
//A list of constant pointers to constant ProtectMes.
list<const ProtectMe* const> guts_;
public:
void add(const ProtectMe& data){
guts_.push_front(&data);
}
};
次のコンパイル エラーが発生します。
エラー: 'const _Tp* __gnu_cxx::new_allocator::address(const _Tp&) const [with _Tp = const ProtectMe* const]' はオーバーロードできません
どこが間違っていたのかを解読しようとして、まだ頭を悩ませています。このコードがコンパイルされないのはなぜですか? 何を変更すればよいですか?