I don’t understand why I’m getting this error. I used the same code previously and it gave me no problem, but now for some reason im getting an error.
outputf3 << "The sorted list is as follows: \n\n";
sorting = new float [function.sort()]; // Here is where the error is.
for (i=0; i < length ; i ++)
{
outputf2 << "\n" << sorting[i] ;
}
For some reason it’s saying
error: expression in new-declarator must have integral or enumeration type
But i used the same thing here in a previous part of the program.
inputs = new float[length];
inputf.clear();
inputf.seekg(0, std::ios_base::beg);
I have no idea why it’s doing this at all.
What I’m doing is reading random numbers in from a file and then sorting them in another part of the function and writeing them out to the output file.
Why do you think:
is the same as
?
Unless
functionis a class instance andsortreturns an integral type, it’s certain it won’t work.The statement:
dynamically allocates
xobjects of typeType. It’s fairly obvious whyxhas to be of integral type.EDIT: As per your comment:
The size to be allocated needs to be of integral type, but you return a
float. But even then, it wouldn’t make sense. You need to return the size ofinputs.