【发布时间】:2015-02-25 14:08:58
【问题描述】:
我无法让 CRTP mixin 工作。
这里是精简的实现:
template < typename T >
class AutoSList : public T {
public:
AutoSList() {}
~AutoSList() : _next(nullptr) {}
private:
static T* _head;
static T* _tail;
T* _next;
};
// I really hate this syntax.
template <typename T>
T* AutoSList<T>::_head = nullptr;
template <typename T>
T* AutoSList<T>::_tail = nullptr;
class itsybase : public AutoSList < itsybase >
{
};
我正在使用 VS2013 并收到以下错误:
error C2504: 'itsybase' : base class undefined
: see reference to class template instantiation 'AutoSList<itsybase>' being compiled
我不知道出了什么问题,有什么建议吗?
【问题讨论】:
-
这是一个错字。您的类名是 AutoSList,但您声明了一个名为 AutoList 的构造函数。与析构函数相同。
-
@AllanDeutsch:请不要在发布答案后更改代码或问题的其他部分。这很容易使答案无效。相反,如果必须,请在问题中添加,但如果该信息使其非常不同,请提出新问题。