Can someone help with this error?

//The error I get is "cannot convert 'int' to 'T*' for argument '1' to 'int readFile(T*,T*,T*,std::istream&)'"
//The error is at the highlighted line below
//readFile.h contains my constant, libraries, and all other necessary things


#include "readFile.h"

int main(){

int x[MAX_SIZE],y[MAX_SIZE],m[MAX_SIZE];

ifstream fin; // declare ifstream object
fin.open("p4p5Data.txt"); // attach file p4p5Data.txt
if (fin.fail()){ // check it out
cout << "\n\aBummer! File p4p5Data.txt"; // report bad news
cout << " could not be opened. Goodbye.";
exit(-1); // outta here
}
int numDataPoints = readFile(x, y, m, fin); // go get data from disk
cout << "\nnumDataPoints = "; // TEMP check data points
cout << numDataPoints;
ofstream fout; // declare ofstream object
fout.open("p4Output.txt"); // attach it to disk file

return EXIT_SUCCESS;
}


int readFile(T x[], T y[], T m[], istream & is){

int numDataPoints = -1; // temp value

return numDataPoints;
}

Is readFile a template function? Then is there template <typename T>?
// Here is my readFile.h

#ifndef PROJ4_H // compile guard
#define PROJ4_H

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>

using namespace std;
const int MAX_SIZE = 200;

typedef long double T; // data type for project

int readFile(T x[], T y[], T m[], istream & is = cin);

#endif // ends PROJ4_H
In fact your function is declared as

int readFile( long double *, long double *, long double *, istream & is = cin);

But you are trying to pass int * See your definitions

int x[MAX_SIZE],y[MAX_SIZE],m[MAX_SIZE];

So the compiler cannot assign int * to long double *
Last edited on
Just talked to my professor and it sounds like he made a couple mistakes in writing this code.

Plus I made some changes. Everything within that main function should be in the readFile function. There is no main function in this .cpp

Now I'm getting an error saying
"undefined reference to 'WinMain@16'
collect2: Id returned 1 exit status"
// Here's what I have now

#include "readFile.h"


int readFile(T x[], T y[], T m[], istream & is){

int numDataPoints = -1; // temp value
is >> numDataPoints;
if (numDataPoints > MAX_SIZE) { // ensure not too big
cout << "\n\n\aTruncating data ";
cout << "due to size constraints.\n\n";
numDataPoints = MAX_SIZE; // truncate if needed
}
for (int i = 0; i < numDataPoints; ++i) { // read data groups
is >> x[i];
is >> y[i];
is >> m[i];
}

ifstream fin; // declare ifstream object
fin.open("p4p5Data.txt"); // attach file p4p5Data.txt
if (fin.fail()){ // check it out
cout << "\n\aBummer! File p4p5Data.txt"; // report bad news
cout << " could not be opened. Goodbye.";
exit(-1); // outta here
}
numDataPoints = readFile(x, y, m, fin); // go get data from disk
cout << "\nnumDataPoints = "; // TEMP check data points
cout << numDataPoints;
ofstream fout; // declare ofstream object
fout.open("p4Output.txt"); // attach it to disk file


return numDataPoints;
}
It seems that you are trying to build a non-console application. Or you did not defined the main function.
Topic archived. No new replies allowed.