문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top