c++ - Linker error: ld symbols not found -


i have class defined follows:

// grid_search.h template<typename element, typename solution, typename oracle> class grid_search : public optimizerinterface<element, solution, oracle> { private:     // ... public:     virtual solution search(const spaceinterface<element>& space, oracle oracle); }; 

and implement in grid_search.cc. use this:

// needed definitions  typedef double (*oracle_f)(vector<int>&); class testspace : public spaceinterface<int> { /* ... */ } static double f(vector<int>& x) { return 0.0; } // ever f  // setup search space , run grid search testspace space(/* ... */); gridsearch<int, vector<int>, oracle_f> *optimizer = new gridsearch<int, vector<int>, oracle_f>(); optimizer->search(space, f); 

then linker error (note compiles , grid_search.cc found fine):

undefined symbols architecture x86_64: "gridsearch<int, std::vector<int, std::allocator<int> >, double (*)(std::vector<int, std::allocator<int> >&)>::search(spaceinterface<int> const&, double (*)(std::vector<int, std::allocator<int> >&))", referenced from:     vtable gridsearch<int, std::vector<int, std::allocator<int> >, double (*)(std::vector<int, std::allocator<int> >&)> in grid_search.cc.o 

i have reviewed several times can't figure out root of error ...

template function definitions need in header file, not .cc file.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -