c++ - STL container as a template parameter -


i'm trying pass stl container template parameter. in case, vector.

here not-functional code:

template<template<class> class tcontainer, class tobject> class foobar { public:      explicit foobar( tcontainer<tobject*> & container )     :     container_( container ){}   private:      tcontainer<tobject*> & container_; };   int _tmain(int argc, _tchar* argv[]) {     std::vector<iunknown*> v;      foobar<std::vector, iunknown*> bla( v );      return 0; } 

is this, i'm trying possible @ all, because compiler cannot swallow this?

there several things wrong code, here working example:

template<template<class, class> class tcontainer, class tobject> class foobar { public:     explicit foobar( tcontainer<tobject*, std::allocator<tobject*>> & container )     :     container_( container ){}  private:     tcontainer<tobject*, std::allocator<tobject*>> & container_; };  int main() {     std::vector<iunknown*> v;     foobar<std::vector, iunknown> bla( v ); } 

the main fault of codes std::vector takes 2 template arguments. looks template<class t, class allocator = std::allocator<t>> class vector;. also, joachim pileborg right double pointer issue, iunknown**. however, simplify code following:

template<class tcontainer> class foobar { public:     explicit foobar( tcontainer & container )     :     container_( container ){}  private:     tcontainer & container_; // careful reference members };  int main() {     std::vector<iunknown*> v;     foobar<std::vector<iunknown*>> bla( v ); // c++11 decltype(v) used } 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -