相关疑难解决方法(0)

为什么直接使用条件运算符而不使用条件运算符进行分配时,该功能指针分配为何起作用?

(本示例中未使用#include,在带有g ++,选项-O0 -g3 -Wall -c -fmessage-length = 0的MacOS10.14,Eclipse IDE上编译)

假设此变量声明:

int (*fun)(int);
Run Code Online (Sandbox Code Playgroud)

无法使用“ std :: toupper和std :: tolower的无效重载”进行编译。

fun = (1 ? std::toupper : std::tolower);   // ERROR, invalid overload
Run Code Online (Sandbox Code Playgroud)

这样编译就可以了:

if (1) {
    fun = std::toupper;   // OK
}
else {
    fun = std::tolower;   // OK
}
Run Code Online (Sandbox Code Playgroud)

c++ pointers overloading function

28
推荐指数
2
解决办法
898
查看次数

标签 统计

c++ ×1

function ×1

overloading ×1

pointers ×1