c++ - Template class calling template function - Linker Error -
i'm experimenting template classes , functions, , ran following error. i'm trying call template function class vertex template class class relationshipexpander. mwe below yields following linker error:
undefined symbols architecture x86_64: "typeinfo pipetype", referenced from: typeinfo relationshipexpander<in> in main.cpp.o "vtable pipetype", referenced from: pipetype::pipetype() in main.cpp.o note: missing vtable means first non-inline virtual member function has no definition. ld: symbol(s) not found architecture x86_64
#include <iostream> #include <vector> #include <forward_list> using namespace std; // abbrr class vertex; typedef forward_list<const vertex*> edge_list; /* * matching */ struct match_first { match_first(unsigned value) : value(value) {}; template<class a> bool operator()(const pair<const unsigned, a> &a) { return a.first == value; } unsigned value; }; /* * edge indirection */ struct in { static edge_list& get_list(pair<edge_list, edge_list> &a) { return a.first; } }; struct out { static edge_list& get_list(pair<edge_list, edge_list> &a) { return a.second; } }; class vertex { public: template<class direction> edge_list &get_edges(unsigned relation_id) { auto = find_if(neigh_set.begin(), neigh_set.end(), match_first(relation_id)); if (i != neigh_set.end()) { return direction::get_list(i->second); } // throw except. } private: vector<pair<const unsigned, pair<edge_list, edge_list>>> neigh_set; }; class pipetype { public: /* * mutators */ virtual void pipe(vertex& gremlin); }; template <class direction> class relationshipexpander: pipetype { public: /* * constructor */ relationshipexpander(unsigned relationship_id) : relationship_id(relationship_id) {}; /* * mutators */ void pipe(vertex& gremlin) { gremlin.get_edges<direction>(relationship_id); }; private: unsigned relationship_id; }; int main() { relationshipexpander<in> expand_in(1); }
pipetype
is different in member function seems not have definition. compiler says:
"vtable pipetype", referenced from:
pipetype::pipetype() in main.cpp.o
note: missing vtable means first non-inline virtual member function has no definition.
if intend pipetype
interface, can make function pure virtual adding = 0
instead of function body. cannot skip implementation, if implemented in derived class.
class pipetype { public: virtual void pipe(vertex& gremlin) = 0; };
if intend class have function implemented, of course have add implementation somewhere. either in header or in 1 of .cpp files.
Comments
Post a Comment