2 つのクラスから継承するクラスがあります。1 つは自分の基本クラスで、もう 1 つはテンプレート クラスです。
typedef typename cusp::csr_matrix< int,
float,
cusp::host_memory > csr_matrix;
class CuspMatrix
:
public csr_matrix,
public Matrix
{
...
}
ある時点で、次のように基本クラス オブジェクトをホストからデバイスにコピーする割り当てを行う必要があります。
cusp::csr_matrix<int,float,cusp::host_memory> A(4,3,6);
cusp::csr_matrix<int,float,cusp::device_memory> A = B;
しかし、それを行う前に、これをその基本クラスcsr_matrixにアップキャストする必要があります
static_castとカスタムキャスト演算子を試しました:
operator csr_matrix()
{
return *( cusp::csr_matrix< int,float,cusp::device_memory> *)this;
}
ただし、実際に実行しようとすると、コンパイラから大量のエラーが発生します
cusp::csr_matrix<int,float,cusp::device_memory> mtx = *(csr_matrix *)this;
実際、静的キャストもこの時点では理解できません。
auto me = static_cast<csr_matrix>( *this );
cusp::csr_matrix<int,float,cusp::device_memory> mtx = me;
それでも、typedef を使用しない C スタイルのショットガン キャストは機能するようです。
auto me = *( cusp::csr_matrix< int,
float,
cusp::host_memory> *)this;
しかし、typedef で失敗します:
auto me = *( csr_matrix *)this;
では、できれば静的キャストを使用して、独自のカスタム オペレーターを使用して安全にアップキャストするにはどうすればよいでしょうか?
完全な namespace::type でのキャストが機能するのに、typedef で失敗するのはなぜですか?