"错误:期望一个类型,在C++中得到'classname'"

Bay*_*Bay 8 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
Run Code Online (Sandbox Code Playgroud)

我越来越:

 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
Run Code Online (Sandbox Code Playgroud)

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

Jam*_*lis 28

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

vector<node<int> > vertices;
Run Code Online (Sandbox Code Playgroud)

(int用作示例;您应该使用您实际需要的类型)

  • 谢谢 - 我在搜索时找到了你的答案,这节省了一些时间. (3认同)