Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"error: Expected a type, got 'classname'" in C++

Tags:

c++

Using the following code:

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

I'm getting:

 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

On the indicated line. Node is clearly defined before b_graph which uses it - what have I done here?

like image 882
Bay Avatar asked Apr 24 '10 18:04

Bay


1 Answers

node is not a class, it's a class template. You need to instantiate it to use it as the element type of vector, e.g.,

vector<node<int> > vertices;

(int is used as an example; you should use the type you actually need)

like image 143
James McNellis Avatar answered Nov 02 '22 05:11

James McNellis