Reputation: 48
I have a multi-file project in VSC++2010, but for some reason it won't link some of them properly.
For example, I have CParser.h and CParser.cpp . CParser.h is just some function declarations:
#pragma once
#include <string>
void parseArg(int argc, char* argv[], GVar gv);
void parseCfg(string cfg, GVar gv)
CParser.cpp just contains implementations:
#include <cstdio>
#include <fstream>
#include <cstring>
#include <string>
#include "_GlobalVar.h" //defines GVar, not relevant
#include "CParser.h"
void parseArg(int argc, char* argv[], GVar &gv) {
/*not really relevant*/
}
And the error:
main.obj : error LNK2019: unresolved external symbol "void __cdecl parseArg(int,char * * const,class GVar)" (?parseArg@@YAXHQAPADVGVar@@@Z) referenced in function _SDL_main
Edit:
There's also this other problem:
template<class T>
void RDAMHandler<T>::clean() {
long i;
while(!avtick.empty())
avtick.pop();
for(i = v.size() - 1; i >= 0; i--) {
delete all[i];
all.pop_back();
v.pop_back();
}
}
And the declaration:
template<class T>
class RDAMHandler {
vector<T*> all;
priority_queue<long> avtick;
vector<bool> v;
public:
T &operator[](long x);
long insert(T &x);
void del(long x);
void clean();
};
I don't see any difference here; what is the problem?
Edit edit: And error
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall RDAMHandler::clean(void)" (?clean@?$RDAMHandler@USDL_Surface@@@@QAEXXZ) referenced in function "void __cdecl cleanUp(class GVar)" (?cleanUp@@YAXVGVar@@@Z)
Upvotes: 1
Views: 289
Reputation: 1521
In CParser.cpp
I think You have to use statement
void CParser::parseArg(int argc, char* argv[], GVar &gv)
instead of
void parseArg(int argc, char* argv[], GVar &gv)
in CParser.cpp file
And In CParser.h
The declaration should be changed to void parseArg(int argc, char* argv[], GVar &gv);
And For Next Error
For Reference Please Go through this 1. Template using class
Hope this will help you.
Upvotes: 1
Reputation: 171127
They're two different overloads - the declaration in the header has GVar gv
, while the definition in the .cpp file has GVar &gv
. One of these is probably a typo.
Upvotes: 1