C++: Can I cast a vector to a vector <base_class> during a function call?

后端 未结 5 917
星月不相逢
星月不相逢 2020-12-20 16:37

I have a existed class and function which look like this:

Class base_class{
    ...
}

void Func(...,vector &vec_b,...){
    // inside          


        
5条回答
  •  余生分开走
    2020-12-20 17:07

    No, you cannot convert between vectors of different types. However, you can achieve what you're trying to do by making Func a template. It probably won't require you to change any code in the actual function body, but it depends on what you're doing.

    template
    void Func(..., vector &vec_b, ...){
        // inside the function, the vector vec_b is being re-organized and re-sized
    }
    

提交回复
热议问题