Here is the actual task: Write a function that usually takes one argument β the address of the string β and outputs this string once. However, if the second argument of the type int specified, which is not equal to zero, then this function outputs the string as many times as there were calls to this function by the time of its given call. (Please note that the number of output lines is not equal to the value of the second argument ; it is equal to the number of function calls by the time of the last call .)
Indeed, this is not a very useful function, but it will force you to apply some of the methods discussed in this chapter. Write a simple program to demonstrate this feature.
This chapter covered: Built-in functions, Reference variables, Passing arguments to a function by reference, Default arguments, Function overloading, Function templates, Function template specifications.
That's what I could write, I know what is wrong. Please tell me how you can solve.
#include <iostream> void out(char* a); void out(char *a, int n); int n = 0; int main() { char ch[] = "Hello"; char * pd = ch; out(pd); out(pd); out(pd); out(pd); out(pd); std::cout << std::endl; out(pd, n); std::cout << std::endl; return 0; } void out(char *a) { std::cout << a << std::endl; n++; } void out(char *a, int n) { if (n != 0) { for (int i = 0; i < n; i++) { std::cout << a << std::endl; } } }