LNK2019

My error:

1>Grades9-13.obj : error LNK2019: unresolved external symbol "void __cdecl fnReadNamesAndScores(class std::basic_ifstream<char,struct std::char_traits<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *,int *)" (?fnReadNamesAndScores@@YAXAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@PAH@Z) referenced in function _main

(I'm missing something obvious, I just know it)

My code:
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
//Declaration in Funcs9Ex13.h
//	Header guard
#ifndef FUNCS9EX13_H
#define FUNCS9EX13_H
//[No namespace declared]
//	Include files

#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <iomanip>

void fnReadNamesAndScores(std::ifstream&, std::string*, int*);

//Definition in Funcs9Ex13.cpp
#include "Funcs9Ex13.h"

using namespace std;

void fnReadNamesAndScores(ifstream &inFile, string *OneDimArrOfStr, int *TwoDimArrOfInt[])
{
	int i = 0;
	while(inFile) {
		inFile >> OneDimArrOfStr[i];
		int score = 0, j = 0;
		while(score) {
			inFile >> TwoDimArrOfInt[i][j];
			j++;
		}
		i++;
	}
}

//Implimentation in Grades9-13.cpp
#include "Funcs9Ex13.h"

using namespace std;

const int NUMB_STUDENTS = 10;
const int NUMB_TESTS = 5;
int main()
{
	ifstream ReadFile;
	fnOpenFiles(ReadFile, "ch9_Ex13Data.txt");

	string arrNames[NUMB_STUDENTS];
	int arrScores[NUMB_STUDENTS][NUMB_TESTS];
	double arrAverageScore[NUMB_STUDENTS];
	char arrGrade[NUMB_STUDENTS];
	double dClassAverage;

	fnReadNamesAndScores(ReadFile, arrNames, *arrScores);
	
		system("pause");
	return 0;


I'm learning using functions to process arrays--so it is most likely something simple.

ERandall
The prototype

void fnReadNamesAndScores(std::ifstream&, std::string*, int*);

differs from the implementation

void fnReadNamesAndScores(ifstream &inFile, string *OneDimArrOfStr, int *TwoDimArrOfInt[])

You can write the function it like so:

void fnReadNamesAndScores(ifstream &inFile, string *OneDimArrOfStr, int TwoDimArrOfInt[NUMB_STUDENTS][NUMB_TESTS])

The compiler needs to know the size of at least the first dimension.
Topic archived. No new replies allowed.