Undefined reference error for one function

Hi, I'm new and I've hit a wall. I have compiled and linked it but the error says: undefined reference to `out(int, std::string, std::string)'
error line: in Main.cpp --> out(val[n],fn[n],ln[n]);


Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <fstream>
#include "main.h"


using namespace std;

int main()
{
    int n = 0;
    string fn[9], ln[9];
    int val[9];

    fname();
    lname();
    kuha();
    out(val[n],fn[n],ln[n]);

    return 0;
}

Header
1
2
3
4
5
6
#include <string>
using namespace std;
int kuha();
string fname();
string lname();
void out(int, string, string);

Source.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "main.h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int kuha()
{
    int grade(0), n(0);
    string f, l;
    string fn[9], ln[9];
    int val[9];
    ifstream take("Photios.txt");
    while (!take.eof())
    {
        while(take >>f >>l >>grade)
        {
            fn[n] = f;
            val[n] = grade;
            n++;
        }
    }
    take.close();
    return val[n];
}

string fname()
{
    int grade(0), n(0);
    string f, l;
    string fn[9], ln[9];

    ifstream take("Photios.txt");
    while (!take.eof())
    {
        while (take >>f >>l >>grade)
        {
            fn[n] = f;
            n++;
        }
    }
    take.close();
    return fn[n];
}

string lname()
{
    int grade(0), n(0);
    string f, l;
    string fn[9], ln[9];

    ifstream take("Photios.txt");
    while (!take.eof())
    {
        while (take >>f >>l >>grade)
        {
            ln[n] = l;
            n++;
        }
    }
    take.close();
    return ln[n];
}

void out(int val[9], string fn[9], string ln[9])
{
    int n;
    ofstream gawas ("Selene.txt");

    for (n = 0; n<9; n++)
    {
        if(val[n] >= 1 && val[n] <= 49)
            {
                gawas<<fn[n] <<" " <<ln[n] <<" F" <<endl;
            }
    else if (val[n] >= 50  && val[n] <= 59)
            {
                gawas<<fn[n] <<" " <<ln[n] <<" E" <<endl;
            }
    else if (val[n] >= 60  && val[n] <= 69)
            {
                gawas<<fn[n] <<" " <<ln[n] <<" D" <<endl;
            }
    else if (val[n] >= 70  && val[n] <= 79)
            {
                gawas<<fn[n] <<" " <<ln[n] <<" C" <<endl;
            }
    else if (val[n] >= 80  && val[n] <= 89)
            {
                gawas<<fn[n] <<" " <<ln[n] <<" B" <<endl;
            }
    else if (val[n] >= 90  && val[n] <= 100)
            {
                gawas<<fn[n] <<" " <<ln[n] <<" A" <<endl;
            }
    }
    gawas.close();
}


Why is it that only the function void out(..) is undefined when it's in the same header as the other functions?
Last edited on
1
2
void out(int, string, string);
void out(int val[9], string fn[9], string ln[9])

This is two different functions because the parameter types are different.
Okay. But what's the difference between int val and int val[n]?
int val is an integer.
int val[n] is an array of n integers.
Last edited on
Oh. I see now. I don't know how to use arrays yet. I only used a friend's code as guide.
I'm gonna read about it first.
Thanks for the help!
Topic archived. No new replies allowed.