在模板中使用std :: max时出错

Pap*_*ohn 0 c++ templates compiler-errors max visual-c++

我可以在模板函数中使用std函数吗?我有补充和写作

#pragma region BlendFunctions

template <class T> 
T BlendLightenf(T x, T y) 
{ 
    return std::max(x, y); //errors here
} 
template <class T> 
T BlendDarkenf(T x, T y) 
{ 
  return std::min(x, y); //errors here
} 
Run Code Online (Sandbox Code Playgroud)

得到

error C2589: '(' : illegal token on right side of '::'
Run Code Online (Sandbox Code Playgroud)

error C2059: syntax error : '::'
Run Code Online (Sandbox Code Playgroud)

在一个字符串中(通常是x和y float).

我定义:

#ifdef MAGICLIB_EXPORTS
#define CPPWIN32DLL_API __declspec(dllexport)
#else
#define CPPWIN32DLL_API __declspec(dllimport)
#endif


#include <stdio.h>
#include <string>
#include <algorithm> 
Run Code Online (Sandbox Code Playgroud)

Jam*_*nze 5

你在使用VC++吗?(错误消息看起来像.)如果是这样,您需要/DNOMINMAX在命令行中添加一个.(在GUI中,它位于配置属性→C/C++→预处理器→预处理器定义.)或者不包含<windows.h>在任何地方(但这很难控制,因为您包含的文件包含其他包含...的文件).