The same program doesn't compile on Windows when using algorithm header

  • Thread starter Thread starter VansFannel
  • Start date Start date
V

VansFannel

Guest
I'm learning C++.

I have written a program that compiles find on Ubuntu 18.04.2, but it doesn't on Windows 7 64 bits.

To compile on Windows I'm using Visual Studio:

Microsoft Visual Studio Enterprise 2017 Version 15.9.12
VisualStudio.15.Release/15.9.12+28307.665

Visual C++ 2017 00369-90013-89248-AA631 <br/>
Microsoft Visual C++ 2017

The errors I get are the following (when I add the `algorithm` header):

c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\algorithm(5367): error C2988: unrecognizable template declaration/definition
c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\algorithm(5367): error C2059: syntax error: '<parameter-list>'
c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\algorithm(5369): error C2143: syntax error: missing ';' before '{'
c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\algorithm(5369): error C2447: '{': missing function header (old-style formal list?)

When I double click on the first error, it goes to the third line of this piece of code:


// FUNCTION TEMPLATE max
template<class _Ty,
class _Pr>
_NODISCARD constexpr const _Ty& (max)(const _Ty& _Left, const _Ty& _Right, _Pr _Pred)
_NOEXCEPT_COND(_NOEXCEPT_OPER(_DEBUG_LT_PRED(_Pred, _Left, _Right)))
{ // return larger of _Left and _Right using _Pred
return (_DEBUG_LT_PRED(_Pred, _Left, _Right) ? _Right : _Left);
}




And my code, that needs `algorithm` header (because I'm using std::find) is in the following method:

#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

std::string ConvertToAStarMap::TruncateMap(const std::string& robot_map)
{
std::string truncatedMap;

std::vector<std::pair<int, int>> list;

int current_x = 0;
int current_y = 0;

std::vector<std::string> map_cells = ConvertToAStarMap::split(robot_map, ';');

for (std::vector<std::string>::iterator it = map_cells.begin(); it != map_cells.end(); ++it)
{
std::vector<std::string> locations = ConvertToAStarMap::split(*it, ',');

double x = std::stod(locations[0]);
double y = std::stod(locations[1]);

if (x < 0)
current_x = static_cast<int>(std::trunc(x));
else
current_x = static_cast<int>(std::trunc(x + 1));

if (y < 0)
current_y = static_cast<int>(std::trunc(y));
else
current_y = static_cast<int>(std::trunc(y + 1));

std::pair<int, int> current = std::make_pair(current_x, current_y);

if (std::find(list.begin(), list.end(), current) != list.end())
{
list.push_back(current);

truncatedMap += std::to_string(current_x) + ",";
truncatedMap += std::to_string(current_y) + ";";
}
}

return truncatedMap;
}





How can fix this error?

Continue reading...
 
Back
Top