eine weitere frage zu templates:
-
ich hab ein problem, und zwar möchte ich eine klasse mit 3 templateparametern ausstatten, wobei parameter 1+2 desweiteren noch als templateparameter für den 3. parameter dienen sollen(hier das Beispiel:
template<class param1,class param2,class param3> class foo{ private: param3<param1,param2> bar; }
ist das irgendwie möglich?
oder muss ich im zweifelsfall den 3. parameter direkt mit allen templates einfügen?
-
typename?
-
invalid template argumentlist^^
-
template <class param1, class param2, template <class, class> class param3> class foo { public: param3<param1,param2> bar; };
nennen sich template template parameter.
-
cool, und schon wieder was gelernt
-
template<class KeyType,class Type,template<class,class> class Container,class Allocator=std::allocator<Type> > class tree{ private: typedef node<KeyType,Container<Type,Allocator> > node; typedef node* pNode; pNode baseNode; pNode begin; pNode end; public: pNode addNode(KeyType Key,Type Value){ } };
ich hab das jetzt so gemacht, aber in der funktion addnode(die ich erstmal nur als testfunktion eingebaut hatte, da der bcb mit mehr als einem templateparameter nich gut klarkommt)wirft er mir beim compilieren nen fatal error:internal compiler error,diesen fehler wirft er später dann jedes mal, wenn ich mit dem mauszeiger über node/pNode komme...
//edit hab jetzt ne möglichkeit gefunden, wie ich das umgehen kann...btw, kann es sein, dass typedefs nich mit vererbt werden? hab das zuerst versucht, doch das wollte der net^^
ok so funktionierts:
template<class Type,class Allocator,template<class,class> class Container> class containerType{ public: typedef Container<Type,Allocator> container; }; template<class KeyType,class Type,template<class,class> class Container,class Allocator=std::allocator<Type> > class tree{ private: typedef node<KeyType,containerType<Type,Allocator,Container>::container> node; typedef node* pNode; pNode baseNode; pNode begin; pNode end; public: pNode addNode(KeyType Key,Type Value){ } };