I have a problem that seems to be a C++ version issue but not a sufficient background to choose vocabulary and labels necessary to lookup or identify my issue.
I have to compile my application on a school server using C++11, but I edit on Replit:
clang++-7 -pthread -std=c++17 -o main Car.cpp CarWash.cpp main.cpp
I run the application on Replit and all values come out fine.
I run the application on the school server and there are incorrect values that occur at specific places in the data processing. So I examined the data. (It is just a text file with a number, newline, number, newline, etc.)
When I call an int return method on a class using a pointer with an arrow operator, only 2 out of 100 values are incorrect. If the int return method should return a small value 0-10 range (but not consistently) I get 281 and then later 47. I tried some casting options to see if that was the issue and also verified the object's values were not strange.
The culprit I think is the math function in car->getWait();
(a simple subtraction problem)
The method is written as:
int Car::getWait()
{
return washStart - timeArrived;
}
I even made other return methods and vars so I could return washStart and timeArrived
separately to perform the operation, then use cout
to display. I get the same specifically large wrong number at specific places while the rest of the operations work fine.
Replit Output:
Returned | |
---|---|
41 | 0.000000 |
42 | 2.000000 |
43 | 4.000000 |
83 | 2.000000 |
84 | 0.000000 |
85 | 1.000000 |
Server Output:
Returned | |
---|---|
41 | 0.000000 |
42 | 281.000000 |
43 | 4.000000 |
83 | 2.000000 |
84 | 37.000000 |
85 | 1.000000 |
Aucun commentaire:
Enregistrer un commentaire