Re: C++11 - Parameter pack question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 15 Aug 2014, Sidney Marshall wrote:

The following code compiles and runs correctly but gives a warning:

----------------------------------------
#include<iostream>

using namespace std;

template<class T>
T sum(T value) {
 return value;
}

template<class T, class ... U>
auto sum(T value, U ... values) {
   return value + sum(values ...);
}

int main() {
 cout << sum(1, 2, 4.6) << endl;
 cout << sum(1, "abcde", 2) << endl;
}
--------------------------------------

$ g++ -std=c++11 pack.cpp
pack.cpp:11:31: warning: â??sumâ?? function uses â??autoâ?? type specifier without trailing return type [enabled by default]
auto sum(T value, U ... values) {

The warning should probably specify that this is a C++14 feature. You should be compiling with -std=c++1y.

--
Marc Glisse




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux