I have a class with a boost::array type that stores references to std::vector.
I want to construct an array of references (I'm trying to DI, or so I think), but haven't succeeded so 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 really get what the compiler is telling me. Does array even work with reference_wrapper?
C:/ide-4.6-workspace/chunkybacon/boost/boost/array.hpp:60: error: no matching function for call to '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 I could just use plain pointers, and it works, but I still have the doubt and, if I can fix it, I'd rather use references.
I'm working with QNX 6.4.1 and GCC 4.3.3.
Thank you in advance for any help =)
reference_wrappers have to be initialized with what to refer to.