Pierwsza część to ze względu na członka wyszukiwanie nazwy, dlatego nie działa.
chciałbym skierować do: 10.2/2 Member name lookup
The following steps define the result of name lookup in a class scope, C. First, every declaration for the name in the class and in each of its base class sub-objects is considered. A member name f in one sub-object B hides a member name f in a sub-object A if A is a base class sub-object of B. Any declarations that are so hidden are eliminated from consideration. Each of these declarations that was introduced by a using-declaration is considered to be from each sub-object of C that is of the type containing the declaration designated by the using-declaration.
If the resulting set of declarations are not all from sub-objects of the same type, or the set has a nonstatic member and includes members from distinct sub-objects, there is an ambiguity and the program is ill-formed. Otherwise that set is the result of the lookup.
Teraz, po kilku z funkcji szablonów.
Zgodnie 13.3.1/7 Candidate functions and argument list
In each case where a candidate is a function template, candidate function template specializations are generated using template argument deduction (14.8.3, 14.8.2). Those candidates are then handled as candidate functions in the usual way. A given name can refer to one or more function templates and also to a set of overloaded non-template functions. In such a case, the candidate functions generated from each function template are combined with the set of non-template candidate functions.
A jeśli dalej czytać 13.3.3/1 Best viable function
F1 jest uważany za lepiej funkcja, jeżeli:
F1 is a non-template function and F2 is a function template specialization
Dlatego następujące kompiluje snippet i uruchamia funkcję bez szablonu bez błędu:
D c;
c.f(1);
Dobre pytanie. Sądzę, że zwykłe reguły rozwiązywania przeciążenia nie mają zastosowania w 'C' (ponieważ zwykle nie szablony są preferowane do szablonów, jeśli istnieje dopasowanie, stąd zachowanie z' D'). –
Dodałbym do pytania OP: "jakakolwiek standardowa reguła C++ wymusza takie zachowanie: jakie jest uzasadnienie tej reguły?" – Vlad
@ Vlad Myślę, że zachowanie jest całkiem rozsądne. Nie spowodowanie tutaj błędu może prowadzić do wielu nieprzyjemnych błędów. Dobre pytanie. – enobayram