class Option;
class Base
{
public:
explicit Base(Option opt);
};
class Derived : public Base
{
public:
using Base::Base;
explicit Derived(const Option &opt);
};
Derived
doit(const Option &opt)
{
return Derived(opt);
}
用GCC 14.2及更早版本编译时,会触发歧义错误:
: In function 'Derived doit(const Option&)':
:19:21: error: call of overloaded 'Derived(const Option&)' is ambiguous
19 | return Derived(opt);
| ^
:6:12: note: candidate: 'Base::Base(Option)'
6 | explicit Base(Option opt);
| ^~~~
:12:15: note: inherited here
12 | using Base::Base;
| ^~~~
:13:12: note: candidate: 'Derived::Derived(const Option&)'
13 | explicit Derived(const Option &opt);
| ^~~~~~~
:9:7: note: candidate: 'constexpr Derived::Derived(const Derived&)'
9 | class Derived : public Base
| ^~~~~~~
:9:7: note: candidate: 'constexpr Derived::Derived(Derived&&)'
Compiler returned: 1