宏"max"需要2个参数,但只给定1个 [英] macro "max" requires 2 arguments, but only 1 given

查看:583
本文介绍了宏"max"需要2个参数,但只给定1个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

template <class T>
struct scalar_log_minimum {
public:
    typedef T value_type;
    typedef T result_type;
    static
        result_type initial_value(){
            return std::log(std::numeric_limits<result_type>::max());
    }
    static
        void update(result_type& t, const value_type& x){
            if ( (x>0) && (std::log(x)<t) ) t = std::log(x);
    }
};

在尝试编译以上代码时出现以下错误:

i got the following error while trying to compile the above:

functional_ext.hpp:55:59:宏"max"需要2个参数,但仅提供1个参数

functional_ext.hpp:55:59: macro "max" requires 2 arguments, but only 1 given

max不是宏,对不对?那这是什么错误呢?顺便说一句,我正在使用Visual Studio 2005

max is not a macro, right? Then what is this error? BTW, I am using visual studio 2005

还有55:59 --- 55是行号59吗?

Also what is 55:59 --- 55 is the line number 59?

推荐答案

我发现包含windows.h后遇到的许多#define非常令人不安(不仅max和min,而且我在使用其他通用词时也遇到了问题如果我没记错的话,请选择"Rectangle").因此,我养成了仅在绝对必要时才包含windows.h的习惯,而从未在头文件中包含.这样可以减少针对特定平台的少量C ++文件的麻烦.

I find the many #defines that you encounter once you included windows.h very disturbing (not only max and min, but I also had problems with other generic words like Rectangle if I'm not mistaken). Therefore, I have developed the habit to include windows.h only when absolutely necessary, and never in header files. This reduces the pain to a small number of C++ files that are platform-specific.

不幸的是,一些Boost库(我相信thread和asio)的标头中确实包含windows.h,但我仍然时常遇到这种愚蠢的问题.

Unfortunately some boost libraries (I believe thread and asio) do include windows.h in their headers, and I still run into this kind of silly problems from time to time.

对于其余导致问题的情况,我的解决方案是在包含头文件后#undef有问题的符号.

My solution for the remainder of the situations where this causes problems is to #undef the problematic symbols after the inclusion of the header files.

这篇关于宏"max"需要2个参数,但只给定1个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆