使用以下代码:
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/