Mailinglist Archive: opensuse-programming (62 mails)

< Previous Next >
Re: [suse-programming-e] STL vector as a function parameter with default value (heres another one for you Jerry...)
  • From: Brad Bourn <brad@xxxxxxxxxxxx>
  • Date: Tue, 15 Feb 2005 08:37:01 -0700
  • Message-id: <200502150837.01552.brad@xxxxxxxxxxxx>
On Saturday 12 February 2005 03:52 am, Michael Stevens wrote:
> This is an error because 'vector<unsigned int>()' is a temporary and you
> can only pass temporaries to 'const' reference parameters. Your function
> must be declared
> func(const vector<unsigned int>& foo);
> OR
> func(vector<unsigned int> foo);
> to work with temporaries.
>


This does allow it to compile, however, once inside the function, I can't use
the std::find function because STL doesn't seem to like const iterators...

here is the error I get
/usr/include/g++/bits/stl_iterator.h: In constructor `
__gnu_cxx::__normal_iterator<_Iterator,
_Container>::__normal_iterator(const
__gnu_cxx::__normal_iterator<_Iter, _Container>&) [with _Iter = const
unsigned int*, _Iterator = unsigned int*, _Container = std::vector<unsigned
int, std::allocator<unsigned int> >]':

/usr/include/g++/bits/stl_iterator.h:598: error: invalid conversion from
`const
unsigned int* const' to `unsigned int*'


B-)

< Previous Next >