I have a existed class and function which look like this:
Class base_class{
...
}
void Func(...,vector<base_class> &vec_b,...){
// inside the function, the vector vec_b is being re-organized and re-sized
}
and I defined a derived class which looks like:
Class derived_class: public base_class{
...
}
Now, without changing the function Func
, can I pass a vector<derived_class>
into Func
, ex:
void main(){
vector <derived_class> d;
Func(...,d,...);
}
such that the derived class d
undergoes the same re-organizing and re-sizing?
I know I can cast derived class to base class in a function call with no problem, but once with a vector into play, there seems to be difficulties? I can't find the answer online, so any suggestions or help is greatly appreciated. thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…