KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to use brace-enclosed initializer lists in a variadic template function, but the compiler complains... am I asking too much or did I do something wrong? This is best demonstrated by example: struct Bracy { Bracy(int i, int j) { } }; struct Test { void consumeOne(int i) { } void consumeOne(const Bracy & bracy) { } void consume() { } template<typename T, typename ...Values> void consume(const T & first, Values... rest) { consumeOne(first); consume(rest...); } template<typename ...Values> Test(Values... values) { consume(values...); } }; void testVariadics() { Test(7,{1,2}); //I'd like {1,2} to be passed to consumeOne(const Bracy & bracy) } GCC (4.7) says: main.cpp:45:14: error: no matching function for call to ‘Test::Test(int, <brace-enclosed initializer list>)’
Tags (comma-separated)
Save Edits
Cancel