问题可能看起来很愚蠢,但我想问..有没有办法我们可以在具有相同签名但不同返回类型(如int fun(int)和float fun(int))的类中声明一个方法,并且在对象期间创建我们可以动态决定要执行哪个函数!我有编译错误...有没有其他方法来实现这个逻辑可能正在使用模板...
您始终可以将返回值作为模板.
template<typename T> T fun(int);
template<> float fun<float>(int);
template<> int fun<int>(int);
Run Code Online (Sandbox Code Playgroud)
你能在运行时动态决定调用哪个?没有.
| 归档时间: |
|
| 查看次数: |
785 次 |
| 最近记录: |