将临时变量绑定到非const引用编译

bind a tempory variable to a non const reference compile on visual

本文关键字:const 引用 编译 绑定 变量      更新时间:2023-10-16
#include<iostream>
struct Foo
{
};
void func(Foo& f)
{
    std::cout << "foo" ;
}
int main()
{ 
    func(Foo());//ok compile
    std::cin.ignore();
    return 1;
}

标准没有说这个国王的东西是不合法的吗?是bug吗?

不应该是合法的。但是一些旧版本的Visual c++(例如VC6)允许这样做。