VS2017(15.8.7 / 15.8.8)无法编译如下代码:
#include <iostream>
class A
{
public:
operator int() const { std::cout << "int() 1" << std::endl; return 0; }
operator int() { std::cout << "int() 2" << std::endl; return 0; }
};
class B : virtual public A {};
class C : virtual public A {};
class D : public B, public C {};
int main()
{
// Compiles when const version is defined before non-const.
// The assignment calls const version of course.
const D cobj;
int i = cobj;
// Compiles when non-const version is defined before const.
// The assignment calls non-const version.
D obj;
int j = obj;
return 0;
}
错误:
g ++ 7.3(默认情况下以及std = c ++ 11/14/17)和VS2013(更新5) 编译时没有任何与转换功能有关的警告/错误 (甚至使用-Wall)。
为什么代码不明确?这是VC ++错误吗?
答案 0 :(得分:0)
这似乎是编译器错误。我在这里报告过:fails to find user-defined-conversion in virtual inheritance
随意投票,以便优先解决问题