私の質問は私が望むほど明確ではないかもしれません。説明させてください。抽象母クラスMと、子クラスC1、C2、... Cnがたくさんあります。それぞれの子で、次のようなテンプレートタイプを定義する必要があります。
class Child1 : public Mother
{
public:
typedef AnotherTemplateClass<Child1,int> Type1_C1;
typedef AnotherTemplateClass<Child1,bool> Type2_C1;
typedef AnotherTemplateClass<Child1,unsigned> Type3_C1;
void DoSomething(Type1_C1 a, Type2_C1 b, Type3_C1);
};
私は次のようなものを定義したいと思います:
class Mother
{
public:
typedef AnotherTemplateClass<this,int> Type1_M;
typedef AnotherTemplateClass<this,bool> Type2_M;
typedef AnotherTemplateClass<this,unsigned> Type3_M;
};
そしてこのタイプを使用するChild1で
class Child1 : public Mother
{
void DoSomething(Type1_M a, Type2_M b, Type3_M c);
};
私はそれが不可能であることを知っています
error: invalid use of ‘this’ at top level
しかし、この問題に答えることができる構文はありますか?
それも可能ですか?
CRTPが役立つ可能性があります:
template <typename Derived>
class ChildCrtp : public Mother
{
public:
typedef AnotherTemplateClass<Derived,int> Type1_C1;
typedef AnotherTemplateClass<Derived,bool> Type2_C1;
typedef AnotherTemplateClass<Derived,unsigned> Type3_C1;
Possibly:
//void DoSomething(Type1_C1 a, Type2_C1 b, Type3_C1);
};
その後
class Child1 : public ChildCrtp<Child1>
{
public:
void DoSomething(Type1_C1 a, Type2_C1 b, Type3_C1);
};
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加