c++ - boost::array of boost::reference_wrapper not compiling -


i have class boost::array type stores references std::vector. want construct array of references (i'm trying di, or think), haven't succeeded far.

class refholder {  public:      boost::array<boost::reference_wrapper<std::vector<int> >, 3> sumsarray;  };  class originalholder {  public:      originalholder(boost::array<boost::reference_wrapper<std::vector<int> >, 3> & psumsarray)     {         sumsarray[0] = boost::ref(_sums);     }  private:      std::vector<int> _sums;  }  int main() {     refholder ref;      originalholder original(ref.sumsarray);      return 0; } 

i don't compiler telling me. array work reference_wrapper?

c:/ide-4.6-workspace/chunkybacon/boost/boost/array.hpp:60: error: no matching function call 'boost::reference_wrapper<std::vector<int, std::allocator<int> > >::reference_wrapper()' c:/ide-4.6-workspace/chunkybacon/boost/boost/ref.hpp:43: note: candidates are: boost::reference_wrapper<t>::reference_wrapper(t&) [with t = std::vector<int, std::allocator<int> >] c:/ide-4.6-workspace/chunkybacon/boost/boost/ref.hpp:33: note:                 boost::reference_wrapper<std::vector<int, std::allocator<int> > >::reference_wrapper(const boost::reference_wrapper<std::vector<int, std::allocator<int> > >&) c:/ide-4.6-workspace/chunkybacon/test/test.cc: in constructor 'refholder::refholder()': c:/ide-4.6-workspace/chunkybacon/test/test.cc:6: note: synthesized method 'boost::array<boost::reference_wrapper<std::vector<int, std::allocator<int> > >, 3u>::array()' first required here  c:/ide-4.6-workspace/chunkybacon/test/test.cc: in function 'int main()': c:/ide-4.6-workspace/chunkybacon/test/test.cc:32: note: synthesized method 'refholder::refholder()' first required here cc: c:/qnx641/host/win32/x86/usr/lib/gcc/i386-pc-nto-qnx6.4.0/4.3.3/cc1plus caught signal 1 

of course use plain pointers, , works, still have doubt and, if can fix it, i'd rather use references.

i'm working qnx 6.4.1 , gcc 4.3.3.

thank in advance =)

when create array have "empty" entries. reference cannot empty (ok, be, it's bad idea), references not work array entries.

consider using boost::smart_ptr<vectorint> > instead. realize that's not want (pointer vs reference) works big point in favor.

------------response question in comments---------

the difference vector of references must referencing objects exist somewhere else -- somewhere manages lifetime of these objects , ensures live longer references them do.

a vector of smart pointers must pointing heap-allocated objects, , manages lifetime of objects.

both of these approaches have valid uses.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -