undefined reference to `ReadFromFile(int&, int&, int**&)'|
Mar 16, 2009 at 9:37am Mar 16, 2009 at 9:37am UTC
Hello,
I get this message from Codeblocks when it tries to link my project files (it compiles them without problems)
undefined reference to `ReadFromFile(int&, int&, int**&)'|
The question is, why does this not work?
The project's files:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
main.cpp:
#include <iostream>
#include <fstream>
#include <vector>
#include "Read.h"
using namespace std;
int main()
{
int n,m;
int ** M = 0;
ReadFromFile(n , m, M); //This is the line, where the linker complains
for (int i = 0;i < n;i++)
{
delete [] M[i];
}
delete [] M;
return 0;
}
Read.h:
1 2 3 4 5 6 7 8
#ifndef READ_H_INCLUDED
#define READ_H_INCLUDED
void ReadFromFile(int & n ,int & m , int ** &M);
#endif // READ_H_INCLUDED
Read.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
#include "Read.h"
#include <iostream>
using namespace std;
void ReadFromFile(int & n ,int & m , int ** &M)
{
ifstream f;
string fn;
bool hiba;
cout << "A fajlnak a kovetkezokeppen kell kineznie: A szamokat szokozzel, vagy ujsor karakterrel kell elvalasztani. Az elso szam a kutyak szama, a masodik a kategoriak szama legyen. Utana pedig kutyankent fel kell sorolni, hogy melyik kategoriaban hany pontot kaptak." << '\n' ;
do {
hiba = false ;
cout << "Add meg a fajl eleresi helyet/nevet !" << '\n' ;
cin >> fn;
//A program megpróbálja megnyitni a fájlt.
f.open(fn.c_str());
if (f.fail())
{
f.clear();
cout << "Nincs ilyen fajl !" << '\n' ;
hiba = true ;
continue ;
}
//Megpróbáljuk beolvasni az input adatok mennyiségét (ennek kell elsőnek lennie a fájlban).
if (!(f >> n) || (n <= 0))
{
f.close();
f.clear();
cout << "A fajl nem megfelelo !" << '\n' ;
hiba = true ;
continue ;
}
if (!(f >> m) || (m <= 0))
{
f.close();
f.clear();
cout << "A fajl nem megfelelo !" << '\n' ;
hiba = true ;
continue ;
}
M = new int *[n];
for (int i = 0;i < n;i++)
{
M[i] = new int [m];
}
//Megpróbáljuk vegigolvasni az inputsorozatot a fájlból.
for (int i = 0;i < n;i++)
{
for (int j = 0;j < m;j++)
{
if ( !(f >> M[i][j]) || (M[i][j] < 0) || (M[i][j] > 10) )
{
hiba = true ;
cout << "A fajl nem megfelelo ! " << '\n' ;
break ;
}
}
}
//Ha megvagyunk, bezárjuk a fájlt.
f.close();
f.clear();
}while (hiba);
}
Mar 16, 2009 at 10:12am Mar 16, 2009 at 10:12am UTC
Last edited on Mar 16, 2009 at 10:13am Mar 16, 2009 at 10:13am UTC
Mar 16, 2009 at 12:11pm Mar 16, 2009 at 12:11pm UTC
It seems you're not linking Read.obj with your program.
Mar 16, 2009 at 6:44pm Mar 16, 2009 at 6:44pm UTC
Maybe transform your function to:
int ** ReadFromFile(int&, int&, int**&)
and your function call to:
int ** M = ReadFromFile(n , m); //This is the line, where the linker complains
I'm still getting the same error.
Mar 16, 2009 at 9:19pm Mar 16, 2009 at 9:19pm UTC
onur
The problem is passing the third parameter by reference. You cannot create a reference to a null-pointer.
I think you are a bit confused..
Topic archived. No new replies allowed.