Vardiac Functions Two Types

Правка en2, от VasuOberoi, 2021-10-10 22:14:37

I am learning vardiac functions and i See two different ways of writing vardiac functions.I m confused which one is best and whats the actual difference between them.

// CODE ---------------------------------------------------------------------------------------

include<bits/stdc++.h>

using namespace std;

// TYPE 1 template<typename... T> void print1(T... args) { ((cout << args << " "), ...); }

// Base empty function void print2() { cout << "\n"; return; }

// TYPE 2 template<typename Head, typename... Tail> void print2(Head H, Tail... args) { cout << H << " "; print2(args...); }

int main() { int x = 5; int y = 6; int z = 7; int r = 4; print1(x, y, z, r); print2(x, y, z, r);

}

// CODE--------------------------------------------------------------------------------------------------------------------

Print 1 and Print 2 both functions accept variable no of arguments.Both will print exact same ans.But in print2 function we are use something like a base empty function Which preserves for last call to the function in call stack.In print1 function We are not using any base function.I want to know the difference between these two functions.

Теги template, variables, function, vardiac functions

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский VasuOberoi 2021-10-10 22:14:37 14
en1 Английский VasuOberoi 2021-10-10 22:13:32 1252 Initial revision (published)