Learning Template in C++, class "is not a class, namespace, or enumeration" error

Viewed 36

This is my .h file:

#include <iostream>
#include <string>
using namespace std;

template <class N> 
class linklist {
  struct node {
    N data;
    node *next;
  };

private:
  node *head;
  node *tail;

public:
  linklist() { head = tail = 0; }
  void addHead(N);
  void addTail(N);
  void delHead(N);
  void delTail(N);
  void printToFile(ofstream);
};


When I try to run my .cpp file using it, it doesn't seem to recognize the class. Here's my class file:

#include "linklist.h"
#include <iostream>
using namespace std;

template <class N>

void linklist::addHead(N addition) {
  // Create new node
  node *temp = new node;
  // Fill node
  temp->data = N
      // Complete linkage
      if (head == 0) {
    head = tail = temp;
  }
}
void linklist::addTail(N addition) {}
void linklist::delHead() {}
void linklist::delTail() {}
void linklist::printToFile(ofstream) {}

And here's the error I get:

./linklist.cpp:7:6: error: 'linklist' is not a class, namespace, or enumeration
void linklist::addHead(N addition) {
     ^
./linklist.h:6:7: note: 'linklist' declared here
class linklist {
      ^

It seems not to be taking issue with the other four methods, but only with addHead. It's giving me the red squiggly underline for linklist in that method, but all the others don't have it. Maybe if I get farther, they'll also give me the error, but IO figured I'd fix it now when I only have one error to fix. I'm not sure what I'm doing wrong here? Any ideas?

0 Answers
Related