1
我有以下模板类。我需要专门针对某些特定的outT
案例alloc
功能。单功能类部分模板专业化,如何解决其他成员的未定义错误
template <typename inT, typename outT>
class Filter {
public:
typedef inT InputType;
typedef outT OutputType;
struct Options {
int a, b, c;
};
virtual void alloc();
};
// Partial template specialization for SpecificOutputType
template < typename inT>
class Filter<inT, SpecificOutputType> {
virtual void alloc();
};
这将导致Options
类和OutputType
被未定义的GCC,例如:
using FilterType = Filter<SomeIn, SpecificOutputType>:
FilterType::Options options;
结果
error: ‘Options’ is not a member of `Filter<SomeIn, SpecificOutputType>`
如果我使用某种类型的比其他的这个错误不会发生SpecificOutputType
。
我该如何解决这个问题?
您的意思是'FilterType :: Options options;'? – user463035818
模板专门化不会复制所有基本模板+所需的编辑...您必须将其放入整个实现中... 或者,您可以使用模板化基类FilterBase,然后使用默认Filter没有修改,并且FilterSpecialisation只需要覆盖您关心的功能。 – UKMonkey