iranano 0 Newbie Poster

In the follwong program a class-type temporary is cast to a refrence and they changed:

struct A 
{
    int a;
    A() { a = 100; }
};
void f(A& x) { x.a = 200; };
int main()
{
    f((A&)A{});
}

No errors in Visual Studio and GCC. But is it safe to use such cast, instead of useing rvalue reference, in Standard C++?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.