mit einigen Vorlagen Experimentieren und deren Verwendungen:Klassenvorlage Konstruktor mit Parameter Pack geben C3520 Fehler
Ich war auf dieser einfachen Struktur, hier zu arbeiten:
template<typename T, size_t n> // templated but not variadic
struct myArray {
static const size_t SIZE = n;
T arr_[SIZE];
myArray() {} // Default Constructor
template<class... U> // Initialization Constructor
myArray(U pack...) { // Templated with variadic parameters of
// type U = T upto SIZE = n;
arr_ = pack...;
}
};
Das möchte ich auf diese Weise verwenden oder ähnlich:
int main() {
myArray<char, 6> arr1{ 'a', 'b', 'c', 'd', 'e', 'f' };
myArray<int, 4> arr2{ 1, 2, 3, 4 };
// Or like this:
myArray<char, 6> arr1 = { 'a', 'b', 'c', 'd', 'e', 'f' };
myArray<int, 4> arr2 = { 1, 2, 3, 4 };
}
und Visual Studio 2017RC ich diesen Compiler-Fehler erhalte:
1>------ Build started: Project: PracticeMath, Configuration: Debug Win32 ------
1>PracticeMath.cpp
1>c:\users\skilz80\documents\visual studio 2017\projects\practicemath\practicemath\practicemath.cpp(19): error C3520: 'U': parameter pack must be expanded in this context
1>c:\users\skilz80\documents\visual studio 2017\projects\practicemath\practicemath\practicemath.cpp(22): note: see reference to class template instantiation 'myArray<T,n>' being compiled
1>c:\users\skilz80\documents\visual studio 2017\projects\practicemath\practicemath\practicemath.cpp(41): fatal error C1903: unable to recover from previous error(s); stopping compilation
1>Done building project "PracticeMath.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Nicht sicher, was ich hier fehlt oder was ich im Initialisierungskonstruktor machen soll.
Vielen Dank die Syntax für die Arbeit mit variadische.. Typen & Vorlagen ist, wo ich stru war Gingeln. –