C++ 使用模板类实例化类时出错
我很难找出我的程序出了什么问题。我在头文件中使用了类声明和成员函数声明,在一个.cpp文件中使用了成员函数定义,然后在main.cpp中使用了一个主驱动程序。我已将它们全部放在ideone上的一个文件中,以便将程序发布到此处: ideone上显示的错误实际上就是我的IDE在构建时显示的错误。有人能指出我做错了什么吗 错误是:C++ 使用模板类实例化类时出错,c++,class,templates,instantiation,doubly-linked-list,C++,Class,Templates,Instantiation,Doubly Linked List,我很难找出我的程序出了什么问题。我在头文件中使用了类声明和成员函数声明,在一个.cpp文件中使用了成员函数定义,然后在main.cpp中使用了一个主驱动程序。我已将它们全部放在ideone上的一个文件中,以便将程序发布到此处: ideone上显示的错误实际上就是我的IDE在构建时显示的错误。有人能指出我做错了什么吗 错误是: prog.cpp: In instantiation of ‘IntDLLNode<int>’: prog.cpp:56: instantiated fr
prog.cpp: In instantiation of ‘IntDLLNode<int>’:
prog.cpp:56: instantiated from ‘void IntDLList<T>::addToDLLHead(const T&) [with T = int]’
prog.cpp:215: instantiated from here
prog.cpp:8: error: template argument required for ‘struct IntDLList’
Line 56: head = new IntDLLNode<T>(el,head,NULL);
Line 215: dll.addToDLLHead(numero);
Line 8: class IntDLLNode {
prog.cpp:在“IntDLLNode”的实例化中:
prog.cpp:56:从“void IntDLList::addtodlhead(const T&)[with T=int]实例化”
prog.cpp:215:从此处实例化
prog.cpp:8:错误:“struct IntDLList”需要模板参数
第56行:head=新的IntDLLNode(el,head,NULL);
第215行:dll.addTodellhead(numero);
第8行:类IntdLNode{
您可以忽略try/catch子句,我还没有完成这部分的工作--我只是试图克服当前的错误。问题在于朋友声明:
template <class T>
class IntDLLNode {
friend class IntDLList;
// rest of IntDLLNode here
};
你能展示更多的代码吗?这些是不同区域的随机行…需要查看定义和一些代码,一些上下文谢谢!按预期工作。
template <class U> class IntDLList;
template <class T>
class IntDLLNode {
friend class IntDLList<T>;
// rest of IntDLLNode here
};