相关疑难解决方法(0)

返回类型是函数签名的一部分吗?

在C++中,返回类型是否被认为是函数签名的一部分?只修改了返回类型,不允许重载.

c++ function

66
推荐指数
2
解决办法
4万
查看次数

为什么我的函数超载不是我的模板优先?

根据这个问题的第一个答案:函数模板重载,"非模板化(或"模板化程度较低")重载优于模板".

#include <iostream>
#include <string>
#include <functional>

void f1 (std::string const& str) {
    std::cout << "f1 " << str << std::endl;
}

template <typename Callback, typename... InputArgs>
void call (Callback callback, InputArgs ...args) {
    callback(args...);
}

void call (std::function<void(std::string const&)> callback, const char *str) {
    std::cout << "custom call: ";
    callback(str);
}

int main() {
    auto f2 = [](std::string const& str) -> void {
        std::cout << "f2 " << str << std::endl;
    };

    call(f1, "Hello World!"); …
Run Code Online (Sandbox Code Playgroud)

c++ templates overload-resolution c++11

4
推荐指数
1
解决办法
257
查看次数

标签 统计

c++ ×2

c++11 ×1

function ×1

overload-resolution ×1

templates ×1