Pregunta

I get an error in my program saying "Unresolved External symbol", i tried everything i know but couldn't solve it. I started getting this error after i used class template.

Here is FileHandler Class Header :-

#include <string>
#include <iostream>
#include "test.h"
#include <iomanip>
#include "Administrator.h"
#ifndef  FileHandler_h
#define FileHandler_h

using namespace std;
template<class T>
class FileHandler
   {
     public:string writeToFile(T writeObject);

public: FileHandler();

   };
  #endif

File Handler Class Implementation

template<class T>
FileHandler<T>::FileHandler(){}

template<class T>
string FileHandler<T>:: writeToFile(T writeObject)
{

   ofstream outputFile;
   outputFile.open("file.txt",ios::out|ios::app);


more code..........

     return "done";
 }

Here is the code where i call the method in filehandler class

string Administrator::registerNewMember(Administrator newAdmin)
{

  FileHandler<Administrator> f1;

    return f1.writeToFile(newAdmin);

}

Below is a screen shot of the error which i get.

enter image description here

How do i fix this error?

¿Fue útil?

Solución

combine "FileHandler Class Header" and "File Handler Class Implementation" in one file.

Otros consejos

Put the definitions from .cpp beside the declarations in the header file .h. Or you need explicit instantiasion.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top