有没有办法禁用将临时绑定到const引用? [英] Is there a way to disable binding a temporary to a const reference?
本文介绍了有没有办法禁用将临时绑定到const引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C ++中,可以将临时绑定到const引用:
In C++ it is possible to bind a temporary to a const reference:
struct A {};
int main() {
const A& a = A();
}
是否有任何方法可以为某些特定的类A禁用此功能不可能将此类的临时对象绑定到const引用吗?
Is there any way to disable this for some particular class A so that it would be impossible to bind a temporary of this class to a const reference?
推荐答案
否,如果需要这样做,您可以在做别的事情。
No, and if you need to do this, you're doing something else wrong.
这篇关于有没有办法禁用将临时绑定到const引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文