1

重複の可能性:
c++ テンプレートの型名反復子

そのようなコードを考えてみましょう:

#include <map>
#include <boost/shared_ptr.hpp>

template <typename T>
class Test
{
     typedef std::map< int, boost::shared_ptr<T> > TMap;
     TMap myMap;

     void test()
     {
         TMap::const_iterator iter = myMap.begin(); // line 12
     }
};

通常のコンパイル後、g++ main.cpp次の行が返されます。

main.cpp: In member function ‘void Test<T>::test()’:
main.cpp:12: error: expected ‘;’ before ‘iter’

に変更std::map< int, boost::shared_ptr<T> >するとstd::map< int, int >、コンパイルされます。

boost::shared_ptr<T>別のテンプレート オブジェクトにパラメーターとして渡されるテンプレート オブジェクトに問題があるようです。

  1. なんで?
  2. これを修正する方法は?
4

0 に答える 0