Mit (mögliche Fehler?):Variable Vorlage in Template-Klasse - unerwarteter Fehler
struct Value
{
template<class T>
static constexpr T value{0};
};
(0) ideone
template<typename TValue>
struct Something
{
void x()
{
static_assert(TValue::template value<int> == 0, "");
}
};
int main() { Something<Value>{}.x(); return 0; }
funktioniert nicht mit Klirren kompilieren ++ 3.6.
error: cannot refer to variable template 'value' without a template argument list
Kompiliert nicht mit g ++ 5.2.
error: ‘template constexpr const T Value::value’ is not a function template
(1) ideone
Kompiliert sowohl mit Klappern ++ ++ und g.
struct Something
{
void x()
{
static_assert(Value::template value<int> == 0, "");
}
};
int main() { Something{}.x(); return 0; }
Warum (0) nicht kompiliert?
Es scheint, dass das Problem auftritt, wenn auf die Variable Vorlage über einen Vorlagenparameter zugegriffen wird (in diesem Fall TValue
). Wenn Sie einen Typalias für TValue
definieren oder das Schlüsselwort typename
verwenden, wird das Problem nicht behoben.
Was geht hier vor?
Was ist 'Vorlage Statischer consExpr T-Wert {0}; soll es tun? Ist es etwas Neues? Wie heißt das? –
@ BЈовић, Es heißt * variable Vorlage *, in C++ 14 hinzugefügt. Siehe [this] (https://en.wikipedia.org/wiki/C%2B%2B14#Variable_templates) (wiki) und [this] (http://en.cppreference.com/w/cpp/language/variable_template) (cppreference) – Nawaz
(0) scheitert für mich am 3.6, mit "kann nicht auf variable template '' value'' ohne eine template argument list " – Barry