【发布时间】:2019-07-01 10:38:07
【问题描述】:
我的问题可能没有我想的那么清楚。 让我解释。 我有一个抽象的母班 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
但是有什么语法可以解决这个问题吗?
这可能吗?
【问题讨论】:
-
什么是
Callback?请提供minimal reproducible example。 -
回调只是一个模板类。为了大家不要误会,我改了名字。
标签: c++ templates inheritance