c++ - Why linker doesn't find my template function declared in class? -
this question has answer here:
well, title says everything. message when linking(compilation successful):
f:/android/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/ ../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.ex e: ./obj/local/armeabi/objs/hellondk/player/renderer.o: in function renderer::on surfacecreated():jni/player/renderer.cpp:63: error: undefined reference 'void gameobject::test<void>()'
gameobject.h:
class gameobject { public: ... template<typename t> t test(); }
gameobject.cpp:
template<typename t> t gameobject::test() { }
renderer.cpp(using template):
object = new gameobject(); ... object->test<void>(); // error here
you must define template functions in header file, otherwise compiler won't know find definition , declaration, gives linker error 1 have.
Comments
Post a Comment