Howard wrote:
"John Black" <bl***@eed.com> wrote in message
news:40***************@eed.com...
Hi,
I have 2 vectors, vector<Derived_class*> vec1, vec2; can I do the
following,
for (int i=0; i<vec1.size(); ++i){
for (int j=0; j<vec2.size(); ++j){
if (.. some comparision of vec1[i] and vec2[j]...){
Base_Class b = vec2[i];
I take it you mean
Base_Class* b = vec2[i];
?
vec2[i] = vec2[j];
vec2[j] = b;
}
}
}
Is there any problem here? In swapping I do not cast the pointer.
Assuming that's what you mean, it's fine.
Somehow I think that conversion between Base_Class* (which is what
'b' is) and Derived_class* (which is what 'vec2[j]' is), requires
a cast (a static_cast, for example).
But, I am still not sure why not use 'std::swap'?
std::swap(vec2[i], vec2[j]);
all type considerations are hidden and taken care of.
Victor