lundi 13 mars 2017

How the Varidic template works in the following cases?

http://ift.tt/2mTwpvi

#include <iostream>
template<typename T> void P(T x) { std::cout << x; }
void foo(char a) {
    P(3);
    P(a);
}
template <typename... A>
void foo(int a, A... args) {
    foo(args...);
    P(a);
}
template <typename... A>
void foo(char a, A... args) {
    P(a);
    foo(args...);
}
int main()
{
    foo('1', '2', 48, '4', '5');
}

//1243548        my result
//12355248       correct result

Question> How the correct result is generated?

Aucun commentaire:

Enregistrer un commentaire