以下代码在各种编译器上输出不同的结果:
最后,它应该如何按照C++标准工作?
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
class Value;
using Array = std::vector<Value>;
class Value
{
public:
Value(const Array &)
{
}
Value(int)
{
}
};
void foo(Array const& a)
{
printf("%d\n", (int)a.size());
}
int main()
{
Array a1 = { 1, 2 };
foo(a1);
foo(Array{ a1 });
foo(Array({ a1 }));
}
Run Code Online (Sandbox Code Playgroud)
PS同样的问题也来自本文的json_spirit库:http://www.codeproject.com/Articles/20027/JSON-Spirit-AC-JSON-Parser-Generator-Implemented