std::vector には型が必要なため、SetData( vector ) を定義することはできません。また、T の定義がない場合、Base で SetData( std::vector< T > ) を定義することは明らかにできません。
したがって、これが本当に必要であり、これが進むべき道だと思う場合は、型のディスパッチを調べる必要があります (または void* を使用してハックする必要があります)。Boost は、いくつかの場所でタイプ ディスパッチを使用します。それ以外の場合は、Google が例を提供します。
それがどのように見えるかの簡単な例を編集します。ディスパッチをタイプするわけではありませんが、より簡単です
class Base
{
public:
template< class T >
bool SetData( const std::vector< T >& t )
{
return SetData( static_cast< const void* >( &t ), typeid( t ) );
}
protected:
virtual bool SetData( const void*, const std::type_info& ) = 0;
};
template< class T >
class Derived : public Base
{
protected:
bool SetData( const void* p, const std::type_info& info )
{
if( info == typeid( std::vector< T > ) )
{
const std::vector< T >& v = *static_cast< const std::vector< T >* >( p );
//ok same type, this should work
//do something with data here
return true;
}
else
{
//not good, different types
return false;
}
}
};