我有
template<typename T>
class queue
{
private:
struct node
{
T data;
std::unique_ptr<node> next; //compile error on incomplete type
node(T&& data_):
data(std::move(data_))
{}
};
std::unique_ptr<node> head;
node* tail;
public:
queue():
tail(nullptr)
{}
我在 VS10 的标记行上收到编译错误。在这种情况下,我是否应该被允许使用不完整的类型(实例化模板 - 构造函数 - 这里以 int 为例)?有解决方法吗?
编辑
singlethreadedqueue.h(62): error C2079: 'queue<T>::node::next' uses undefined class 'std::unique_ptr<_Ty>'
1> with
1> [
1> T=MyClass
1> ]
1> and
1> [
1> _Ty=queue<MyClass>::node
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\memory(2161) : see reference to class template instantiation 'queue<T>::node' being compiled
1> with
1> [
1> T=MyClass
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\memory(2195) : see reference to class template instantiation 'std::_Unique_ptr_base<_Ty,_Dx,_Empty_deleter>' being compiled
1> with
1> [
1> _Ty=queue<MyClass>::node,
1> _Dx=std::default_delete<queue<MyClass>::node>,
1> _Empty_deleter=true
1> ]
1> singlethreadedqueue.h(69) : see reference to class template instantiation 'std::unique_ptr<_Ty>' being compiled
1> with
1> [
1> _Ty=queue<MyClass>::node
1> ]
1> : see reference to class template instantiation 'queue<T>' being compiled
1> with
1> [
1> T=MyClass
1> ]