C++ same function parameters with different return type

前端 未结 10 1071
猫巷女王i
猫巷女王i 2020-12-16 18:25

I need to find some way to mock an overload of a function return type in C++.

I know that there isn\'t a way to do that directly, but I\'m hoping there\'s some out-o

10条回答
  •  遥遥无期
    2020-12-16 19:07

    If you know your value can never be something like zero or negative, just return a struct holding int and double and zero out the one you don't need...

    It's a cheap and dirty, but easy way...

    struct MyStruct{
    int myInt;
    double myDouble;
    };
    
    MyStruct MyFunction(){
    }
    

提交回复
热议问题