Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 获得';未在此范围内声明';错误_C++ - Fatal编程技术网

C++ 获得';未在此范围内声明';错误

C++ 获得';未在此范围内声明';错误,c++,C++,我不明白为什么会产生这个错误。有人能解释一下我做错了什么吗?Max没有像你认为的那样接受三个参数 In file included from /usr/local/gcc4.9.0/include/c++/4.9.0/bits/char_traits.h:39:0, from /usr/local/gcc4.9.0/include/c++/4.9.0/string:40, from /usr/local/gcc4.9.0/include/c++/4.9.0/stdexcept:39, from





我不明白为什么会产生这个错误。有人能解释一下我做错了什么吗?

Max没有像你认为的那样接受三个参数

In file included from /usr/local/gcc4.9.0/include/c++/4.9.0/bits/char_traits.h:39:0,
from /usr/local/gcc4.9.0/include/c++/4.9.0/string:40,
from /usr/local/gcc4.9.0/include/c++/4.9.0/stdexcept:39,
from /usr/local/gcc4.9.0/include/c++/4.9.0/array:38,
from std_lib_facilities_4.h:27,
from hw4pr4.cpp:1: /usr/local/gcc4.9.0/include/c++/4.9.0/bits/stl_algobase.h: In instantiation of ‘const _Tp&                                           std::max(const _Tp&, const _Tp&, _Compare) [with _Tp = double; _Compare = double]’:
 hw4pr4.cpp:35:36: required from here
/usr/local/gcc4.9.0/include/c++/4.9.0/bits/stl_algobase.h:264:26: error: ‘__comp’ cannot be used as    a function
if (__comp(__a, __b))

Max不像你想象的那样接受三个论点

In file included from /usr/local/gcc4.9.0/include/c++/4.9.0/bits/char_traits.h:39:0,
from /usr/local/gcc4.9.0/include/c++/4.9.0/string:40,
from /usr/local/gcc4.9.0/include/c++/4.9.0/stdexcept:39,
from /usr/local/gcc4.9.0/include/c++/4.9.0/array:38,
from std_lib_facilities_4.h:27,
from hw4pr4.cpp:1: /usr/local/gcc4.9.0/include/c++/4.9.0/bits/stl_algobase.h: In instantiation of ‘const _Tp&                                           std::max(const _Tp&, const _Tp&, _Compare) [with _Tp = double; _Compare = double]’:
 hw4pr4.cpp:35:36: required from here
/usr/local/gcc4.9.0/include/c++/4.9.0/bits/stl_algobase.h:264:26: error: ‘__comp’ cannot be used as    a function
if (__comp(__a, __b))

带有三个参数的
std::max
的唯一重载用于给出前两个参数中的较大者,将第三个解释为要使用的比较函数,而不是
带有三个参数的
std::max
的唯一重载用于给出前两个参数中的较大者,将第三解释为比较函数,而不是<代码> @ GWW是正确的,但是如果使用C++ 11编译器,则会有一个新的变量变化——只需提供一个初始化器列表,而不是多个ARG,即多个ARG:

double d=max(abs(a), max(abs(b), abs(c)));
                     ^^^^              ^
void new_double(双a、双b、双c)
{
双d=最大值({abs(a),abs(b),abs(c)});

CUT< P> @ GWW是正确的,但是如果使用C++ 11编译器,则会出现一个新的变量变化——只需要提供一个初始化器列表,而不是多个ARG:
double d=max(abs(a), max(abs(b), abs(c)));
                     ^^^^              ^
void new_double(双a、双b、双c)
{
双d=最大值({abs(a),abs(b),abs(c)});

难道你的标题上写着“未在此范围内声明”吗(消息周围没有引号,这使得你的标题很难阅读)。该消息未出现在您的问题正文中。此外,请更新您的问题以显示完整的代码示例。您的实际代码必须具有一个或多个
#include
指令;我们需要查看它们。您的标题为“未在此范围内声明”(信息周围缺少引号,使标题很难阅读)。该信息不会出现在问题正文中。另外,请更新您的问题以显示完整的代码示例。您的实际代码必须有一个或多个
#include
指令;我们需要查看它们。谢谢:double d=max(abs(a),abs(b) );d=max(d,abs(c));double d=max(abs(a),abs(b));d=max(d,abs(c));
double d=max(abs(a), max(abs(b), abs(c)));
                     ^^^^              ^
void new_doubles(double a, double b, double c)
{
    double d = max( { abs(a), abs(b), abs(c) } );
    cout << d;
}