Sunday 25 September 2016

c++ - error LNK2019: unresolved external symbol error?

Can any1 tell me why I'm getting this error.



template header file (prog.h):



#include 
#include

#include
#include
#include
using namespace std;

#ifndef H_PROG
#define H_PROG

// data files


#define D1 "data1.txt"

#define INT_SZ 4 // width of integer
#define FLT_SZ 7 // width of floating-pt number
#define STR_SZ 12 // width of string

#define INT_LN 15 // no of integers on single line
#define FLT_LN 9 // no of floating-pt nums on single line
#define STR_LN 5 // no of strings on single line


// function and class prototypes

// stores items from input file into vector
template < class T >
void get_list ( vector < T >&, const char* );

#endif


.cpp file :




#include "prog.h"
#include


template < class T >
void get_list ( vector < T >& vector1, const char* filename )
{
ifstream infile;
ofstream outfile;


infile.open(filename);
if(infile.fail())
{
cout<<"File did not open."< }
else
{
T data;
while(infile)

{
infile>>data;
vector1.insert(data);
}
}
}


in the main function I have :




#include "prog.h"
#include

int main ( )
{
vector < int > v1;
vector < float > v2;
vector < string > v3;



// first heap

cout << "first heap - ascending order:\n\n";
get_list(v1,D1);

_getch();
return 0;
}






when i try to run this i get an error saying :



error LNK2019: unresolved external symbol "void __cdecl get_list(class std::vector > &,char const *)" (??$get_list@H@@YAXAAV?$vector@HV?$allocator@H@std@@@std@@PBD@Z) referenced in function _main

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...