c++ - Passing user defined class as template parameter -
i trying implement graph in c++.
have defined class edge take node name , weight 2 parameters.
, class graph, when tried pass edge template parameter in graph declaration graph<int,edge> g, got error.
can't pass class template parameter. new c++ coding, please pardon me stupidity. can suggest correct way it?
template<class t1,class t2> class edge{ t1 d_vertex; t2 d_weight; public: edge(t1,t2); t1 vertex(); t2 weight(); }; template<class t1,class t2> edge<t1,t2>::edge(t1 v,t2 w):d_vertex(v),d_weight(w){ } template<class t1,class t2> t1 edge<t1,t2>:: vertex(){ return d_vertex; } template<class t1,class t2> t2 edge<t1,t2>::weight(){ return d_weight; } template<class t,class t2> class graph{ vector<pair<t, list<t2> > > node; }; int main() { graph<int,edge> g; }
in instantiation
graph<int,edge> g; edge still class template. implies either graph class should
template<class t, template<class,class> class t2> class graph{ /**/ }; ie having template template parameter or should specify type of edge, eg
graph<int, edge<int,int>> g;
Comments
Post a Comment