struct A
{
enum InnerEnum { X };
A(InnerEnum x)
{}
};
int main()
{
A a(X);
}
The compiler complains: error C2065: 'X' : undeclared identifier
The compiler knows what the constructor's parameter type is, so when I pass X as the argument, the compiler should know it is a valid argument.
I know this is not ADL(Argument-dependent Name Lookup, also known as Koenig Lookup), but I think it's useful and pretty handy. Because I don't have to write as follows:
A a(A::X);
I think the ADL rule should be generalized to such a case.
Am I right?
Name lookup is the procedure by which a name, when encountered in a program, is associated with the declaration that introduced it. For example, to compile std::cout << std::endl;, the compiler performs: unqualified name lookup for the name std , which finds the declaration of namespace std in the header <iostream>
No, C++11 does not support ALL the features of C11. It does not even support all the features of C99. Variable-length arrays, for example, were introduced in C99, but C++ does not yet support them.
Function calls in C++ are subject to function overload resolution. Overload resolution is driven by the argument types. I.e. the language "works" specifically in that direction: from argument types to specific version of the function with the given name.
You are proposing to introduce a reverse process - argument type deduction based on function name. This will not work in general case. It might work in cases when there's only one candidate function (as in your example), but, again, in is contrary to principles that work in the general situation when the function is overloaded.
Of course, the situation will get even more complicated when name lookup on unqualified name X
can see something else named X
in addition to your A::X
. I think it can easily get very counterintuitive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With