Während this lesen, ich bin verwirrt durch die folgenden Beispiele:Funktion Vorlage Spezialisierung
// Example 2: Explicit specialization
//
template<class T> // (a) a base template
void f(T);
template<class T> // (b) a second base template, overloads (a)
void f(T*); // (function templates can't be partially
// specialized; they overload instead)
template<> // (c) explicit specialization of (b)
void f<>(int*);
// ...
int *p;
f(p); // calls (c)
Hier (c)
ist eine explizite Spezialisierung von (b)
.
// Example 3: The Dimov/Abrahams Example
//
template<class T> // (a) same old base template as before
void f(T);
template<> // (c) explicit specialization, this time of (a)
void f<>(int*);
template<class T> // (b) a second base template, overloads (a)
void f(T*);
// ...
int *p;
f(p); // calls (b)! overload resolution ignores
// specializations and operates on the base
// function templates only
Hier (c)
ist eine explizite Spezialisierung von (a)
. Warum das? Liegt das an der Bestellung der Deklaration?
Offhand würde ich nur "ja" sagen, und angenommen, der Code ist gültig, das ist die einzig mögliche Antwort. Aber die Frage ist, ob der zweite Code gültig ist. Ich glaube, dass es gültig ist, aber das im Standard zu finden könnte viel Arbeit sein ... –
@Alf P. Steinbach: Warum konnte der zweite Code nicht gültig sein? – Donotalo
@Donato: ignoriere die Autoren (die Really (TM) kennen ihre Sachen, wenn es um Vorlagen geht) Ich bin nur vorsichtig von Code, der Reihenfolge-abhängige oder andere "willkürliche" Wirkung hat. Der Standard soll vor solchen Dingen schützen, nämlich zweistufige Zusammenstellung von Vorlagen schützt vor solchen Dingen. Also ich habe nur ein <0.5% glauben, dass es nur eine Regel gibt, dann möglicherweise eine, die keine Diagnose benötigt. –