[C++] Why doesn't it compile?

Slightdust

Member
Sep 18, 2005
172
0
0
To simplify the process, please try to compile the codes:

http://pastebin.com/m15312450

I use Dev-C++ and it tells me that there's a linking error...but for the LIFE of me I can't figure out how to make changes to fix it!!

I need some fresh eyes and ideas please.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Well the code doesn't necessarily help all that much with a linker error. You should also post the makefile. In general a linker error will be caused by not linking the correct object modules to the program (so a function the linker is looking for doesn't exist), or by using the wrong declaration types for names in an external module (so a function the linker is looking for seems not to exist), or by using different and imcompatible compilation modes, that sort of thing.

Post the makefile and the details of the linker error.
 

Aikouka

Lifer
Nov 27, 2001
30,383
912
126
You had some funky things going on... let me elaborate:

typedef Collumns record[MAX]; //Array int 20

With this, you define a type "record" that creates an array of 20 Collumns... yet you never use it and actually define each as:

Collumns record[MAX]; //initialize array record

This doesn't hurt compiling at all, but it is kind of awkward :eek:.

Mark, Mr. Slightdust did not post the linker error or else you would've been able to pinpoint the problem. I downloaded Dev-C++ and tried to compile it myself. That showed that there was a problem with readFile().

To fix it, make these changes:

definition:
void readFile(ifstream&, int&, int&, Collumns*);

use:
readFile(inFile, count, loopCounter, record); //read file

declaration:
void readFile(ifstream& inFile, int& count, int& loopCounter, Collumns * record)


You could also use this notation which seems closer to what you had:

definition:
void readFile(ifstream&, int&, int&, Collumns[]);

use:
readFile(inFile, count, loopCounter, record); //read file

declaration:
void readFile(ifstream& inFile, int& count, int& loopCounter, Collumns record[])
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Mark, Mr. Slightdust did not post the linker error or else you would've been able to pinpoint the problem. I downloaded Dev-C++ and tried to compile it myself. That showed that there was a problem with readFile().

Nice of you to do that. It's the step I wasn't up for last night :).