简体   繁体   English

具有功能的通用引用

[英]Universal references with functions

What is the type of "univ" in the code below? 下面的代码中“ univ”是什么类型?

template<typename T>
void func(T&& univ) {
    // ??
}

int sum(int a, int b) {
 return a+b;   
}

int main() {

    func(sum);

}

I didn't know that universal references also worked with functions. 我不知道通用引用也可以与函数一起使用。 Is func(sum); func(sum); equivalent to func(&sum); 等同于func(&sum); or is the rvalue reference binding itself to something else than a simple pointer? 还是右值引用将自身绑定到除了简单指针之外的其他东西?

I don't really know how to put this into more words... 我真的不知道该如何用更多的话来表达...

The type is reference to function taking two int s and returning and int 类型是对采用两个int并返回int int的函数的引用

or, as a comment says: int(&)(int, int) 或者,如评论所述: int(&)(int, int)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM