Aracthor
Aracthor

Reputation: 5907

Min and max functions with Visual Studio

I have the following code in one of header files (lib.hpp file) of my project:

#ifndef SLIM_MATHS_LIB_HPP_
# define SLIM_MATHS_LIB_HPP_

namespace slim
{
namespace maths
{

namespace lib
{
template <typename T>
inline T        min(T a, T b); // Many errors on this line (see below)
// Other functions
}
}
}

# include "lib.ipp" // Functions definitions are inside

#endif // !SLIM_MATHS_LIB_HPP_

It compiled and worked very well with GCC on GNU/Linux system.

Now I am trying to compile it with Visual Studio 14.0 on Windows 10, and I got plenty of error on min function definition line, as following:

Error C2146 syntax error: missing ')' before identifier 'a' slim3d-core C:\Users\msi\Desktop\SLIM3D\inc\slim\maths\lib.hpp 23
Error C2433 'T': 'inline' not permitted on data declarations slim3d-core C:\Users\msi\Desktop\SLIM3D\inc\slim\maths\lib.hpp 23
Error C2365 'T': redefinition; previous definition was 'template parameter' slim3d-core C:\Users\msi\Desktop\SLIM3D\inc\slim\maths\lib.hpp 23
Error C2061 syntax error: identifier 'a' slim3d-core C:\Users\msi\Desktop\SLIM3D\inc\slim\maths\lib.hpp 23
Error C2059 syntax error: ')' slim3d-core C:\Users\msi\Desktop\SLIM3D\inc\slim\maths\lib.hpp 23
Error C2146 syntax error: missing ')' before identifier 'b' slim3d-core C:\Users\msi\Desktop\SLIM3D\inc\slim\maths\lib.hpp 23
Error C2146 syntax error: missing ';' before identifier 'b' slim3d-core C:\Users\msi\Desktop\SLIM3D\inc\slim\maths\lib.hpp 23

I already successfully compiled it with Visual Studio 14.0 on a Windows 7 system, but lib.hpp and lib.ipp were respectively named lib.hh and lib.hpp, so I think it is a system problem from Windows 10 or an extention problem.
Maybe Visual Studio refuse to consider content of .ipp file as C++ code, as it doesn't color it as code when I open it. However, as it is included from an .hpp file and not directly added to solution, there shouldn't be a difference.

Upvotes: 2

Views: 7912

Answers (1)

1201ProgramAlarm
1201ProgramAlarm

Reputation: 32742

min is defined as a macro in windows.h. Add a #undef min line to your header before declaring your function.

Upvotes: 2

Related Questions