クラスTestがあります:
typedef enum
{
AA, BB
} TType;
template <typename T>
struct TVector
{
typedef std::vector <T> Type;
};
template < typename T, const TType type >
class Test
{
private:
typename TVector <T>::Type it;
};
および再定義された operator = による特殊化 (追加機能はありません):
template < typename T, const TType type >
class Test <T *, type>
{
public:
Test <T *, type > & operator = ( const Test <T*, type > &source ) {return *this;}
template <TType type2>
Test <T *, type > & operator = ( const Test <T*, type2 > &source ){return *this;}
template <TType type2>
Test <T *, type > * operator = ( const Test <T*, type2 > *source ) {return *this;}
};
異なる TType パラメータを持つオブジェクトを互いに割り当てようとしていますが、この手順は正しく機能します。
int _tmain(int argc, _TCHAR* argv[])
{
Test <double *, AA> a1;
Test <double *, BB> b1;
a1=b1; //Correct
Test <double *, AA> *a2;
Test <double *, BB> *b2;
a2 = b2; //Error
return 0;
}
ただし、ポインターを使用した同じ手順は機能しません。エラー コードを参照してください。
Error 1 error C2440: '=' : cannot convert from 'Test<T,type> *' to 'Test<T,type> *' 49
互いに異なる TType パラメータを持つポインタを割り当てることは可能ですか (どのように?)?
更新された質問:
また、ポインターとオブジェクトの間の代入についてはどうでしょうか?
a2 = &b1; //Error
*a2 = b1; //Unitialized memory
コードサンプルをお願いできますか? ご協力いただきありがとうございます。