以前はC++でテンプレートと動的バインディングの両方を使用していましたが、最近それらを一緒に使用しようとすると、コンパイルが不可能であることがわかりました。
私がやろうとしていることは次のようなものです:
std::map<MyClass, unsigned int> mymap;
MyClassは、動的メモリバインディングを利用するクラスです。数時間検索した後、これはまだ解決できない影響を引き起こしているという印象を受けたので、この問題とその解決方法についてのガイダンスを期待していました。
私の最終的な目標は、次のようなことができるようにすることです。
std::vector<MyClass> MyClassPool;
//fill the vector with MyClass objects...
for(usigned int i=0 ; i<MyClassPool.size() ; i++)
{
mymap[ MyClassPool[i] ] = i;
}
さまざまな方法でポインタを使用してみましたが、機能せず、何ができるかわかりません。
上記で次のエラーが発生します。
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_function.h: In member function `bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Instance]':
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_map.h:338: instantiated from `_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = Instance, _Tp = float, _Compare = std::less<Instance>, _Alloc = std::allocator<std::pair<const Instance, float> >]'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_function.h:227: error: no match for 'operator<' in '__x < __y'