Calling a function in main from a templated class

I am trying to call my 'run' function from my LinkedList.cpp file. This is what I've done so far

1
2
3
4
5
6
7
8
9
10
  #include <iostream>
  #include "Node.h"
  #include "LinkedList.h"

  int main()
  {
       LinkedList<T> myList(); 
       myList.run(); 
       return(0);
  }


The errors I am getting are:

error: 'T' was not declared in this scope
LinkedList<T> myList();
error: template argument 1 is invalid
LinkedList<T> myList();
error: request for member 'run' in 'myList', which is of non-class type 'int()'
myList.run();
You are supposed to substitute T in main with whatever type you want to store in the linked list.

You'll also have to remove the parentheses at the end of line 7, otherwise the compiler will think you're declaring a function.
In your main function, you'll want to actually provide a valid type to the template parameter. 'T' is not a valid type.
Alright, thank you. Here is where I'm at now:

1
2
3
4
5
6
7
8
9
10
  #include <iostream>
  #include "Node.h"
  #include "LinkedList.h"

  int main()
  {
       LinkedList<int> myList;
       myList.run(); 
       return(0);
  }


The new error is:
main.cpp:(.text+011): undefined reference to LinkedList<int>LinkedList()
Does LinkedList.h contain the definition of the LinkedList constructor?
Yes it does. Everything else compiles except the main.
When you say:
Everything else compiles except the main.
to what everything else are you referring?
I solve this issue. I had an undefined pointer in my LinkedList class. After that the program worked fine.
Topic archived. No new replies allowed.