Ana Tayffy
Ana Tayffy

Reputation: 39

Getting trouble with template argument

This is my 1st template and I get some errors when running this code. Any help would be great!

class polinom;

template <typename Tip>
class node {
  node <Tip>* next;
  Tip coef;
  int grad, nr;
public:
  friend class polinom;
};

class polinom
{
protected:
  node<Tip>* prim;      <--------- THIS LINE
};             

ERRORS : "Tip" was not declared in this scope and template argument 1 is invalid

Upvotes: 0

Views: 38

Answers (1)

Beta
Beta

Reputation: 99094

The template statement applies to the thing that follows it, not to the rest of the file. So as it stands, your polinom is not a template class. Try this:

template <typename Tip>
class polinom;

template <typename Tip>
class node {
  node <Tip>* next;
  Tip coef;
  int grad, nr;
public:
  friend class polinom<Tip>;
};

template <typename Tip>
class polinom
{
protected:
  node<Tip>* prim;
};         

Upvotes: 1

Related Questions