Variadic Templates example

后端 未结 5 2172
别那么骄傲
别那么骄傲 2021-02-07 20:20

Consider following code, I don\'t understand why empty function of print must be defined.

#include 
using namespace std;

void print()
{   
}   
         


        
5条回答
  •  囚心锁ツ
    2021-02-07 20:46

    If you don't have empty print function, imagine a call with 2 parameters :

    1. print (a, b) => cout << a << endl and call print(b)
    2. print (b) => cout << b << endl and call print()

    oups, print() doesn't exists, because only print with at least one parameter exists ! So you need a print without parameters.

    print without any parameters is your final call

提交回复
热议问题