CPP/DefaultArguments

From ProgrammingExamples
< CPP
Revision as of 18:38, 8 July 2010 by FirstPerson (Talk | contribs)

Jump to: navigation, search

DefaultArguments.cpp

#include <iostream>
 
using namespace std;
 
template<typename T>
void printNTimes(const T& arg, int n = 1){
 for(int i = 0; i != n; ++i){
   cout << arg << endl;
  }
}
 
int main(int argc, char *argv[])
{
  printNTimes("hello",5);
  printNTimes("goodbye");
  return 0;
}