C++ C++;具有多重继承的构造函数重载解析

C++ C++;具有多重继承的构造函数重载解析,c++,inheritance,constructor,multiple-inheritance,overload-resolution,C++,Inheritance,Constructor,Multiple Inheritance,Overload Resolution,我有一小段代码,我想了解更多关于重载解析为什么选择一个构造函数而不是另一个构造函数的信息。下面是有问题的代码: #include <iostream> struct Base { }; struct Other { Other(const Other&) { std::cout << "Copy Constructor\n"; } Other(const Base&) { std

我有一小段代码,我想了解更多关于重载解析为什么选择一个构造函数而不是另一个构造函数的信息。下面是有问题的代码:

#include <iostream>

struct Base
{

};

struct Other
{
    Other(const Other&)
    {
        std::cout << "Copy Constructor\n";
    }
    Other(const Base&)
    {
        std::cout << "Custom Constructor\n";
    }
};

struct Derived : public Base, public Other
{
    Derived() :
        Other(*this)
    {

    }
};

int main()
{
    Derived derived;    // Prints "Copy Constructor"

    system("pause");
    return 0;
}
#包括
结构基
{
};
结构其他
{
其他(常数其他&)
{

std::cout问题代码段编译的原因是Visual Studio的非标准一致性行为(我目前使用的是VS2017.3 Preview,它编译代码时即使使用/permissive-标志也没有错误)。下面是GCC和Clang发出的错误:

海湾合作委员会 叮当声
从中获取的输出错误。

在我的编译器中对clang/gcc的不明确调用不明确,无法编译。嗯,很有趣。我正在使用Visual Studio 2017.3(预览),甚至可以使用/permission-flag进行编译。我假设这是Visual Studio的非标准行为,而不是Clang/GCC的非标准行为?是的,它在VC++上成功编译。请参阅实时演示
Error(s):
source_file.cpp: In constructor ‘Derived::Derived()’:
source_file.cpp:25:20: error: call of overloaded ‘Other(Derived&)’ is ambiguous
         Other(*this)
                    ^
source_file.cpp:16:5: note: candidate: Other::Other(const Base&)
     Other(const Base&)
     ^
source_file.cpp:12:5: note: candidate: Other::Other(const Other&)
     Other(const Other&)
     ^
Error(s):
source_file.cpp:25:9: error: call to constructor of 'Other' is ambiguous
        Other(*this)
        ^     ~~~~~
source_file.cpp:12:5: note: candidate constructor
    Other(const Other&)
    ^
source_file.cpp:16:5: note: candidate constructor
    Other(const Base&)
    ^
1 error generated.