La prima parte è dovuto al membro ricerca del nome, ecco perché fallisce.
mi riferisco a: 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.
Ora, per la materia con funzioni template.
Come per 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.
E se si continua a leggere 13.3.3/1 Best viable function
F1 è considerato un meglio funzione, se:
F1 is a non-template function and F2 is a function template specialization
Ecco perché i seguenti compilazioni frammento ed esegue la funzione senza modello senza errori:
D c;
c.f(1);
fonte
2012-04-02 11:19:40
Buona domanda. Immagino che le solite regole di risoluzione da sovraccarico non si applichino in 'C' (dato che normalmente i template non sono preferiti ai template se c'è una corrispondenza, da qui il comportamento con' D'). –
Vorrei aggiungere alla domanda dell'OP: "qualsiasi regola standard C++ impone un tale comportamento: qual è la logica alla base di questa regola?" – Vlad
@Vlad Penso che il comportamento sia abbastanza ragionevole. Non causare qui un errore potrebbe aprire la strada a molti bug sgradevoli. Buona domanda però. – enobayram