0

One of the answers in SO states that we cannot bind a non const l-value reference to an r-value. This is a sample code.

#include <iostream>

using namespace std;

struct Position2D
{
    float m_x;
    float m_y;

    Position2D(float x, float y) : m_x(x), m_y(y)
    {
    }
};

int main()
{
    Position2D& p2 = Position2D(2, 2); // this is the line which has the problem.
    Position2D&& p3 = Position2D(2, 2);

    return 0;
}

The problem is Visual Studio 2013 compiler compiles above mentioned code segment without any error. But online c++11 compiler shows an error as the link which included in SO answer describes. Who is correct? Is there any problem in Visual Studio 2013 C++ compiler with new C++11 standards?

Community
  • 1
  • 1
Amith Chinthaka
  • 1,015
  • 1
  • 17
  • 24

0 Answers0