小编Ser*_*bir的帖子

下面的C++ 11代码应该如何工作?

以下代码在各种编译器上输出不同的结果:

  • 在Visual Studio 2013上的2,1,2
  • Visual Studio 2015上的2,2,2
  • 关于GCC5/c ++ 14的2,1,1
  • 使用Microsoft Codegen在Clang 3.7上获得2,2,2
  • 在Ubuntu 14.04下的Clang 3.6/c ++ 11上的2,1,2

最后,它应该如何按照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

gcc clang visual-c++ c++11

6
推荐指数
1
解决办法
138
查看次数

标签 统计

c++11 ×1

clang ×1

gcc ×1

visual-c++ ×1