-
错误输出
error C2589: “(”: “::”右边的非法标记
error C2059: 语法错误 : “::” -
错误代码举例
[c-sharp] view plaincopy
size.Width = std::max(size.Width, elementSize.Width);
3. 函数模板max
[c-sharp] view plaincopy
template inline
const _Ty& (__CLRCALL_OR_CDECL max)(const _Ty& _Left, const _Ty& _Right)
{ // return larger of _Left and _Right
return (_DEBUG_LT(_Left, _Right) ? _Right : _Left);
}
注:模板就是实现代码重用机制的一种工具,它可以实现类型参数化,即把类型定义为参数, 从而实现了真正的代码可重用性。模版可以分为两类,一个是函数模版,另外一个是类模版。
-
错误原因
函数模板max与Visual C++中的全局的宏max冲突。
-
解决办法
第一种办法:设置项目属性,在预定义处理器中添加定义NOMINMAX来禁止使用Vsual C++的min/max宏定义。
项目属性 ——> C/C++ ——> 预处理器 ——> 预处理器定义 (此处添加预定义编译开关 NOMINMAX)
第二种办法: 加上括号,与Vsual C++的min/max宏定义区分开
[c-sharp] view plaincopy
size.Width = std::max(size.Width, elementSize.Width);
修改为:
[c-sharp] view plaincopy
size.Width = (std::max)(size.Width, elementSize.Width);
大家软件写完了可以考虑发表成果,软件著作权,价格低至300元。https://item.taobao.com/item.htm?spm=a230r.1.14.11.59ef22acsmWnEI&id=577657291213&ns=1&abbucket=11#detail