I keep getting errors and i dont know what im doing wrong.I've included just pieces of these three files. The compiler is giving me errors and i dont know what's wrong.

this is my header file List.h not all but some of it.

#include <iostream>
using namespace std;

#ifndef INTEGERLIST_H
#define INTEGERLIST_H

template <class T>
class List
{
 public:
  List(int sz);                   //Constructor create array with sz capacity

  //The big three
  ~List();                        //Destructor
  List(const List &initList);     //Copy constructor
List &operator=(const List &rightSide);  //Assigment operator



  //Name: getSize
  //Description:  returns the number of elements in the array
  //Parameteres:  none
  //Return:  number of elements in the array
  int getSize() const;

This is my implementation file list.cpp

#include "list.h"

#include <iomanip>
using namespace std;

template <class T >

List::List(int sz)                   //Constructor creates array with capacity sz

{
  numElements = sz;
  list = new T [sz];
}

This is my application file

#include "list.cpp"
#include "list.h"
#include <iostream>
#include <fstream>
using namespace std;

void initializeList(List<char> &array);
void printList(List<char> array);
void updateItem(List<char> &array);
int menu();


int main()
{
  List<char> myList(10);
Member Avatar for danb737

You have to place your template class definition in the same place as the declaration.
See C++ FAQ 35.12 up to 35.15.

thank you for responding.


okay so my header is okay.so in lines 6-12 i would put:

template <class T>
List<T>::List()
{
numElement=sz:
list= new int[sz];
}

Yes except for what is sz and where are you getting it from? Do you have all of your code in List.h now? What does your main .cpp file look like now?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.