std::vector<std::reference_wrapper<Type>> vec;
//Some stuff...
for(int i = 0; i < vec.size(); i++)
{
if(&vec[i] == &type)
{
returntrue;
}
}
This is not working. I am completely new to std::reference_wrapper, so I guess I'm not sure to work with it. This above example gives me a 'lacks a cast'
I have another spot where I do something like:
vec[i].someMethod();
This gives me:
__gnu_cxx::__alloc_traits<std::allocator<std::reference_wrapper<Type> > >::value_type’ has no member named 'someMethod()'
You can pass them to functions that expect Type or Type& arguments, and you can use them to initialize Type& variables, but you can't call their Type members with the member access notation. It'd be vec[i].get().someMethod();