How do I set parameter default values that rely on other parameters?

前端 未结 2 1900
臣服心动
臣服心动 2021-01-07 10:23

The following code compiles and works as expected.

#include 

void function(std::vector vec, int size=1);

int main(){
    std::vect         


        
2条回答
  •  被撕碎了的回忆
    2021-01-07 11:26

    Why do you need second parameter if it based on the first?

        void function(std::vector vec ){
            size_t size = vec.size();
            //code..
            return;
        }
    

    Isn't it easier?

提交回复
热议问题