void readData(ifstream& file, char& operation,
              int& numOfData)
// Purpose: To read data from a file specified by the user
{
   file>>operation>>numOfData;
   if(operation == 'I')
   {
      Array<int>* array;
      array = new Array<int>(numOfData);
   }
}

That's where the problem is coming from.

const int DEFAULT_SIZE = 30;

template <class ItemType>
class Array
{
   private:
      ItemType *data;
      int size;

   public:
      Array(int size = DEFAULT_SIZE);
      Array(const Array &);
      ~Array();

      ItemType& operator[](int);
      int getSize();
      void operator=(const Array<ItemType> &);
};  // class Array

That's my header.

template <class ItemType>
Array<ItemType>::Array(int size)
// purpose: allocate a dynamic array using the size passed to the
//          constructor.
// preconditions: size is positive.
// postconditions: a dynamic array is allocated based on the size and
//          the instance variable size is set to the size of the array.
{
   data = new ItemType[size];
   this -> size = size;
}  // set value constructor

And that's the constructor
For some reason I get an undefined ref error when I'm using the exact same thing my professor gave us except I changed it from passing long to passing int as a data type and it complied his but not mine.

Member Avatar for r.stiltskin

This is basically a guess, because you provide only snippets of your code and a vague description of the error. For the future -- it would be better to post the exact error message, and more complete code so we can see the file structure, preprocessor directives, etc.

Anyway, did you separate the template declaration and its definition into separate files (.h and .cpp)? If so, that's your problem -- put all of the template code together in the header file.

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.