C+中节点的继承+; 我在C++中编写了一个双链表,并有一个类:“代码>节点< /代码>,我用它来做一个单独链表。下面显示了类的定义

C+中节点的继承+; 我在C++中编写了一个双链表,并有一个类:“代码>节点< /代码>,我用它来做一个单独链表。下面显示了类的定义,c++,inheritance,C++,Inheritance,Node.h 简单地说,我的驱动程序如下: driver.cc #包括 #包括“DoublyLinkedList.h” int main() { DLLNode试验; 返回0; } 编译时,会出现以下错误: ./DoublyLinkedList.h:7:24: error: expected class name class DLLNode : public Node { ^ ./DoublyLinkedList.h:9:18: error: ty

Node.h

简单地说,我的驱动程序如下:

driver.cc

#包括
#包括“DoublyLinkedList.h”
int main()
{
DLLNode试验;
返回0;
}
编译时,会出现以下错误:

./DoublyLinkedList.h:7:24: error: expected class name
class DLLNode : public Node {
                       ^
./DoublyLinkedList.h:9:18: error: type 'Node<int>' is not a direct or virtual base of 'DLLNode<int>'
                DLLNode<T>() : Node<T>(), prev() {}
                               ^~~~~~~
driver.cc:6:15: note: in instantiation of member function 'DLLNode<int>::DLLNode' requested here
        DLLNode<int> test;
/DoublyLinkedList.h:7:24:错误:应为类名
类DLLNode:公共节点{
^
./DoublyLinkedList.h:9:18:错误:类型“Node”不是“DLLNode”的直接基或虚拟基
DLLNode():Node(),prev(){}
^~~~~~~
driver.cc:6:15:注意:在这里请求的成员函数'DLLNode::DLLNode'的实例化中
DLLNode试验;
我不明白为什么类
节点
没有被识别为我的编译器在第一个错误中声称的类。任何提示都将不胜感激


我的编译器是苹果LLVM 6.0版(clang-600.0.57)(基于LLVM 3.5svn)

继承时,需要将模板类型参数传递给模板基类:

template <typename T>
class DLLNode : public Node<T> {
                        // ^^^
   // ...
};
模板
类DLLNode:公共节点{
// ^^^
// ...
};

类DLLNode:public Node{
在您的示例中,
节点
是一个模板化的类。这就是为什么编译器无法识别它!多亏了你们两位,请尝试
节点
。我不知道必须包含模板。它工作起来很有魅力。
#include <iostream>
#include "DoublyLinkedList.h"

int main() 
{
    DLLNode<int> test;

    return 0;
}
./DoublyLinkedList.h:7:24: error: expected class name
class DLLNode : public Node {
                       ^
./DoublyLinkedList.h:9:18: error: type 'Node<int>' is not a direct or virtual base of 'DLLNode<int>'
                DLLNode<T>() : Node<T>(), prev() {}
                               ^~~~~~~
driver.cc:6:15: note: in instantiation of member function 'DLLNode<int>::DLLNode' requested here
        DLLNode<int> test;
template <typename T>
class DLLNode : public Node<T> {
                        // ^^^
   // ...
};