Hey,
I keep getting this error 2019 in my project. I suspect it has something to do with my operator<< functions,
since it only pops up each time I call the <<operator in my main function, but I can't seem to find what's wrong.
My header :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#ifndef H_Herexamen
#define H_Herexamen
#include <cstdlib>
#include <string>
#include <iostream>
#include <map>
#include <vector>
template <class T> class dataMap {
private:
std::map<int, T> data;
public:
dataMap(){};
~dataMap(){};
dataMap(const dataMap& d);
std::map<int, T> getMap();
void addElement(int i, T t);
void removeElement(int i);
T operator[](int i);
template <class T> friend std::ostream& operator<<(std::ostream& output, const dataMap<T>& operand);
};
template <class K> class nodeList {
private:
std::vector<K> nodes;
public:
nodeList(){};
~nodeList(){};
nodeList(const nodeList& n);
std::vector<K> getList();
void addNode(K k);
template <class K> friend std::ostream& operator<<(std::ostream& output, const nodeList<K>& operand);
};
#endif H_Herexamen
|
My main function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <cstdlib>
#include <string>
#include <iostream>
#include <map>
#include <vector>
#include "Herexamen.h"
using namespace std;
//dataMap functions
template <class T> map<int, T> dataMap<T>::getMap(){
return data;
}
template <class T> dataMap<T>:: dataMap(const dataMap<T>& d){
this.data = d.data;
}
template <class T> void dataMap<T>::addElement(int i, T t){
data.insert(pair<int, T>(i, t));
}
template <class T> void dataMap<T>::removeElement(int i){
map<int, T>::iterator it = data.find(i);
data.erase(it);
}
template <class T> T dataMap<T>::operator[](int i) {
return data[i];
}
template <class T> ostream& operator<<(ostream& output, dataMap<T>& operand) {
int i=0;
map<int, T> temp = operand.getMap();
map<int, T>::iterator it = temp.begin();
for(i=0;i<temp.size();i++) {
if(it!=NULL) output<<it->first<<it->second<<endl;
it++;
}
return output;
}
//nodeList functions
template <class K> vector<K> nodeList<K>::getList(){
return nodes;
}
template <class K> nodeList<K>::nodeList(const nodeList<K>& n){
nodes = n.nodes;
}
template <class K> void nodeList<K>::addNode(K k){
nodes.push_back(k);
}
template <class K> ostream& operator<<(ostream& output, nodeList<K>& operand){
int i=0;
vector<K> temp = operand.getList();
for(i=0;i<temp.size();i++) {
output<<temp[i]<<'\t';
}
return output;
}
//main function
int main(int argc, string argv) {
return 0;}
|
The error :
Error 2 error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> >
& __cdecl operator<<<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >
(class std::basic_ostream<char,struct std::char_traits<char> > &,class nodeList<class std::basic_string
<char,struct std::char_traits<char>,class std::allocator<char> > > const &)" (??$?6V?$basic_string
@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV
?$nodeList@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@@Z) referenced in function _main Herexamen.obj