最初に少し長いサンプルコードと質問をお詫び申し上げます... A、B、Cの3つのクラスがあります(AとBは抽象です)。C++、コピーコンストラクターの実装、デフォルトのテンプレートパラメーター
クラスAは、異なるタイプのItemのオブジェクトを格納するコンテナを表します。
template <typename Item>
struct TList {typedef std::vector <Item> Type;};
template <typename Item>
class A
{
protected: typename TList <Item>::Type items;
A() : items (0) {}
virtual ~A() = 0 {}
};
派生クラスBには、Item *の特殊化機能がいくつか追加されており、既定のパラメータはTDです。
typedef enum { D1, D2} TD;
template < typename T, const TD td = D1 >
class B;
template <typename Item, const TD td>
class B <Item *, td> : public A <Item *>
{
public:
B() : A <Item *>() {}
template <const TD td2>
B (const B <Item *, td2> & source)
{
if (this != &source) { //Code } //Error
}
virtual ~B() = 0 {}
};
クラスCは抽象型ではなく、別の追加機能(コードには含まれていません)が含まれています。
template < typename T, const TD td = D1 >
class C;
template <typename Item, const TD td>
class C <Item *, td> : public B <Item *, td>
{
public:
C() : B <Item *, td>() {}
template <const TD td2>
C (const C <Item*, td2 > &source) : B <Item*, td> (source) {}
};
デフォルトパラメータがタイプであるならば、私はクラスCの2つのオブジェクトを作成しようとしています場合は、すべてがOKです。
しかし、両方のパラメータのタイプが異なる場合
int main()
{
C <Test <double> *, D1 > t1;
C <Test <double> *, D2 > t2(t1);
}
コンパイラは、行の次のエラーで
if (this != &source) { //Code } //Error
に停止します。
Error 1 error C2446: '!=' : no conversion from 'const B<T,td> *' to 'B<T,td> *const
私の質問へコード:
1)(どこのクラスで)どこにTDの異なる直径のコピーコンストラクタを実装するか。
2)どこのクラスでどのようにTDの異なる太さに対してoperator =を実装するか。
3)(どこのクラスで)デストラクタを実装するか。
ご協力いただきありがとうございます。
@ KennyTM:これら2つのオブジェクトが異なるタイプであることを忘れました。ご協力いただきありがとうございます。 – justik