Bay
Bay

Reputation: 121

"error: Expected a type, got 'classname'" in 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?

Upvotes: 12

Views: 13245

Answers (1)

James McNellis
James McNellis

Reputation: 354979

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)

Upvotes: 29

Related Questions