我正在学习C ++。
我编写了一个可以在Ubuntu 18.04.2上编译find的程序,但是在Windows 7 64位上却没有。
要在Windows上进行编译,我使用的是Visual Studio:
Microsoft Visual Studio Enterprise 2017版本15.9.12 VisualStudio.15.Release / 15.9.12 + 28307.665
Visual C ++ 2017年00369-90013-89248-AA631
Microsoft Visual C ++ 2017年
我得到的错误如下(当我添加algorithm
标头时):
c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\algorithm(5367): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\algorithm(5367): error C2059: syntax error: '<parameter-list>'
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\algorithm(5369): error C2143: syntax error: missing ';' before '{'
1>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?)
当我双击第一个错误时,它将转到这段代码的第三行:
// 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);
}
我的代码需要algorithm
头(因为我使用的是std :: find),它的代码如下:
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <limits>
#include <sstream>
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;
}
如何解决此错误?
更新:
如果包含Windows.h
标头,则会出现以下错误:
warning C4003: not enough arguments for function-like macro invocation 'min'
error C2589: '(': illegal token on right side of '::'
error C2062: type 'unknown-type' unexpected
error C2059: syntax error: ')'
warning C4003: not enough arguments for function-like macro invocation 'max'
error C2589: '(': illegal token on right side of '::'
error C2062: type 'unknown-type' unexpected
error C2059: syntax error: ')'
在以下代码中:
// Init max and min variables.
int max_x = std::numeric_limits<int>::min();
int min_x = std::numeric_limits<int>::max();
更新2:
ConvertToAStarMap.h => https://pastebin.com/PEHEvhSm
ConvertToAStarMap.cpp => https://pastebin.com/Y4JWiyVU
Main.cpp => https://pastebin.com/6LdQKVpP
答案 0 :(得分:2)
由于标题中的lateral view explode(split(maxxx.OBJET_METIER, '\073')) om as splitted_col
,您似乎遇到了名称冲突。 C ++标准库在struct max {}
中有一个std::max
函数模板,Windows.h标头定义了一个<algorithm>
类似函数的宏(除非您在包含标头之前max
)。
我建议您为#define NOMINMAX
选择一个不同的名称(并且更有意义),以避免名称冲突。