1
ich ein Problem mit dem folgenden Code haben:Vorbei std :: initializer_list als nicht-Typ Template-Argument
#include <deque>
#include <initializer_list>
#include <string>
struct EnumItem
{
inline operator int() const {
return id;
}
std::string name;
int id;
};
template <const std::initializer_list<EnumItem>& items>
class Enum
{
public:
private:
static const std::deque<EnumItem> _items;
};
template <const std::initializer_list<EnumItem>& items>
const std::deque<EnumItem> Enum<items>::_items{ items };
int main()
{
Enum<{{"0", 0}}> test;
return 0;
}
Es ist nicht, wirft Fehler über meine test
Instanziierung zahlreiche Syntax nicht kompilieren:
2>error C2059: syntax error : '{'
2>error C2143: syntax error : missing ';' before '{'
2>error C2143: syntax error : missing '>' before ';'
2>error C2976: 'Enum' : too few template arguments
2>: see declaration of 'Enum'
2>error C2447: '{' : missing function header (old-style formal list?)
2>error C2059: syntax error : '>'
Was mache ich falsch und wie mache ich das richtig?
Ich bin mir ziemlich sicher, dass Sie kein Template-Argument vom Typ 'std :: initializer_list' haben können. –
@BaummitAugen: warum nicht? Kann ich überhaupt kein Template-Argument haben? –
Erlaubte Typen sind meistens Ints und Pointer. (Vollständige Liste [hier] (http://en.cppreference.com/w/cpp/language/template_parameters).) Sie könnten stattdessen ein Parameter-Pack verwenden. –