Trying to update to a pointer from a function return. Just for background this is a template that acts like the stl vector. This is the returning function.
////////////////////////////////////////////////////////////////////////////////
//removes an item from the array
const T& remove(int pos)
{
if(pos > cnt)
pos = cnt;
if(pos < 0)
pos = 0;
static T v;
for(int i,k = 0; i < cnt; i++,k++)
{
if(i == pos)
{
v = element[i];
i++;
}
else
element[k] = element[i];
}
cnt--;
return v;
}
/////////////////////////////////////////////////////////////////////////
The pointer variable I am trying to update:
TVector<Member*> members;
Member* backmember;
backmember = members.remove(members.size()-1);
but backmember always returns null. I am sure I am missing something simple, just not sure what. Any ideas? Let me know if you have any questions and thanks in advance.
removereturns aconst T&. Yourbackmembertakes a pointer, which is not the same thing as a reference. It also takes a non-constpointer. So that's two ways that this code is wrong. Are you sure this is the code in question? How does this compile, let alone returnNULL?