Error: function overloading

Here is a small program demonstrating function overloading, there is a problem with the char version of print_arr, it causes the program to crash and I don't know what's wrong. I copied it from a book and as far as I can tell I copied it correctly.

EDIT: Also this book doesn't explain what ** means. Is that a pointer to a pointer?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std;

void print_arr(int* arr, int n);
void print_arr(double* arr, int n);
void print_arr(char **arr, int n);

int a[] = {1,1,2,3,5,8,13};
double b[] = {1.4142, 3.141592};
char* c[] = {"Inken, Blinken, Nod"};

int main()
{
    print_arr(a,7);
    print_arr(b,2);
    print_arr(c,3);
    return 0;
}

void print_arr(int* arr, int n) {
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}

void print_arr(double* arr, int n) {
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}

void print_arr(char** arr, int n) {
    for (int i = 0; i < n; i++)
        cout << arr[i] << " " << endl;
}
Last edited on
You forgot some quotation marks, so your last array only has one element.
just for addition, it should written:
 
char* c[] = {"Inken", "Blinken", "Nod"};
Thanks, damn typos in my book :(
Topic archived. No new replies allowed.