I included these libraries into my source file main.cpp
:
#include <iostream>
#include <climits>
My entire code written in Visual Studio 2017, Windows.
I transferred my code file to Linux.
When I try to compile with g++ Item.cpp main.cpp -o main
, it gives an error for this part:
items[size - 1]->points = std::numeric_limits<int>::min();
So errors below:
main.cpp: In function ‘void insert_p(Item**, int, int&)’:
main.cpp:287:33: error: ‘numeric_limits’ is not a member of ‘std’
items[size - 1]->points = std::numeric_limits<int>::min();
^~~~~~~~~~~~~~
main.cpp:287:48: error: expected primary-expression before ‘int’
items[size - 1]->points = std::numeric_limits<int>::min();
^~~
A correct solution would be just replacing #include <climits>
with #include <limits>
.
Unfortunately, here is the challenge: Is it possible to solve this issue without changing my source code?
Is there any compiling trick to fix this?
I'm looking for a command like g++ Item.cpp main.cpp -o main -llimits
to link <limits>
library.
[EDIT]:
Solved my problem with command below:
g++ Item.cpp main.cpp -o main -include "limits"
Check this: https://stackoverflow.com/a/3387518/7977464
And as @user4581301 said:
It's far better to fix the code.
Thank you all.