This question already has an answer here:
In the main.cpp
I have
#include "helper.h"
#include <list>
using namespace std;
int main(int argc, const char * argv[]) {
//switch between list and vector
list<int> a = {0, 1};
list<char> b = {'a', 'b'};
func(a, b);
return 0;
}
My helper.h
looks like
template <class C1, class C2>
void func(C1 &a, C2 &b)
and my helper.cpp
looks like
#include <list>
#include "helper.h"
template <class C1, class C2>
void func (C1 &a, C2 &b)
{
//do stuff
}
Then building it in Terminal on Mac with g++ main.cpp mysort.cpp -o sorting -std=c++11
generates the error "function func has internal linkage but is not defined"
and Undefined symbols for architecture x86_64:
"void func<std::__1::list<char, std::__1::allocator<char> >, std::__1::list<int, std::__1::allocator<int> >, main::$_0>(std::__1::list<char, std::__1::allocator<char> >&, std::__1::list<int, std::__1::allocator<int> >&, main::$_0)", referenced from:
_main in main-202a16.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Aucun commentaire:
Enregistrer un commentaire