小编ris*_*ngh的帖子

使用模板作为模板参数的功能

如何将具有模板参数的函数传递给其他函数?

template <class _T>
void inc(int &x) {
    x++;
}

template <class FUNC>
void add(int &x, FUNC f) {
    f(x);
}

int main() {
    int x = 0;
    add(x, inc);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

所以,我得到"错误:没有匹配函数来调用'添加'".

c++ templates

3
推荐指数
2
解决办法
73
查看次数

标签 统计

c++ ×1

templates ×1