سؤال

I'm unsure why the following code works (VC++ 2013):

void Foo(std::vector<int> &v) { }

In main:

std::vector<int> v;
Foo(std::move(v));

Because there is no Foo defined which takes an rvalue parameter or a const lvalue reference I was under the impression the above code would fail to compile. What is going on?

Thank you

هل كانت مفيدة؟

المحلول

That code cannot work. It must horribly break under any standard-conforming compiler. You're trying to initialize a non-const reference to an lvalue from an rvalue. Nope, won't work.

It is to be noted that both GCC and Clang reject it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top