次のコードに基づいて、Baseへのポインタを'Controller'クラスに格納するにはどうすればよいですか?
template< class Derived >
class Base
{
public:
template < typename T >
void Serialise( T* t )
{
Derived* d = static_cast< Derived* >( this );
d->Serialise( t );
}
};
class Derived : public Base< Derived >
{
public:
template < typename T >
void Serialise( T* t )
{
printf( "serialising to object T\n" );
}
};
したがって、Serialise関数を呼び出してシリアル化するオブジェクトを渡すControllerクラスがある場合、必要なときにオブジェクトの型の一部であるため、派生型がわかっているポインターを格納する必要があります。実際の型が何であるかを知らずにBase型を使用します。
class Controller
{
public:
void DoSerialise();
private:
Base< Derived >* m_myObject; // I want this to just be Base* m_myObject but cant due to template!
};