c++ - C++ 中的 "error: Expected a type, got ' 类名 '"

标签 c++

使用以下代码:

template <typename T>
class node {
    [. . .]
};
class b_graph {
friend istream& operator>> (istream& in, b_graph& ingraph);
friend ostream& operator<< (ostream& out, b_graph& outgraph);

public:

    [...]
private:
    vector<node> vertices; //This line

我得到:

 error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::vector’
 error: expected a type, got  'node'
 error: template argument 2 is invalid

在指示的行上。节点在使用它的 b_graph 之前明确定义 - 我在这里做了什么?

最佳答案

node 不是一个类,它是一个类模板。您需要实例化它以将其用作 vector 的元素类型,例如,

vector<node<int> > vertices;

(以int为例,您应该使用您实际需要的类型)

关于c++ - C++ 中的 "error: Expected a type, got ' 类名 '",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2705707/

相关文章:

c++ - 将已编译的库添加到 CMake Qt 项目?

c++ - 模板化函数语法错误中使用的模板化类中的嵌套类

c++ - 在 Hadoop 2.x 中运行 C++ 代码

c++ - 如何在 C++ 中使用 setprecision

c++ - 为 mysql 列序列化 Int 数组 C++

c++ - 指向 glutDisplayFunc 函数的指针

c++ - 32 位 8 位比较形成的 32 位汉明字符串

c++ - 读取直方图后未处理的异常(使用 calcHist 创建)

c++ - 将 unique_ptr<Derived> 转换为 unique_ptr<Base>

c++ - 为什么内存分配器不主动将释放的内存返回给操作系统?