C++ g++;调用私有副本构造函数而不是构造函数

C++ g++;调用私有副本构造函数而不是构造函数,c++,compiler-errors,g++,C++,Compiler Errors,G++,这是违规代码。它在VisualStudio2010下编译,但在g++3.4.x和4.1.x下编译失败。我无法立即访问最近的g++版本,因此无法进行检查 #include <iostream> struct Color { enum Colors { red, blue, green, yellow }; Color(Colors c) : col(c) {} private: Colors col; Color(const Color& c)

这是违规代码。它在VisualStudio2010下编译,但在g++3.4.x和4.1.x下编译失败。我无法立即访问最近的g++版本,因此无法进行检查

#include <iostream>

struct Color {
  enum Colors {
    red, blue, green, yellow
  };

  Color(Colors c) : col(c) {}

private:
  Colors col;
  Color(const Color& c);                                 // line 12
  Color& operator=(const Color& c);
};

std::ostream& operator << (std::ostream& os, Color const&) { return os; }

int main()
{
  std::cout << Color(Color::red) << std::endl;  // line 20
}
#包括
结构颜色{
枚举颜色{
红,蓝,绿,黄
};
颜色(颜色c):col(c){}
私人:
颜色颜色;
颜色(const Color&c);//第12行
颜色和运算符=(常量颜色和c);
};

std::ostream和操作员。但考虑到名称空间
Foo
的使用不匹配,我认为这不是您真正的代码。编译器如何确定最适合方法的重载?它是否忽略了访问修饰符来定位最合适的匹配项,即const&version?FWIW,这里有一个固定版本正在处理最近的GCC:你确定这个确切的代码没有编译,因为你显然发布了一个修改过的版本,没有显示你的真实代码吗?@Samuel“是否忽略访问修饰符来定位最合适的匹配项,即const&version?”没错,选择正确的名称后会检查访问。