Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.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++ 这段代码可以在我的PC上编译,但不能在标准C++;98竞争服务器上的编译器_C++_C++98 - Fatal编程技术网

C++ 这段代码可以在我的PC上编译,但不能在标准C++;98竞争服务器上的编译器

C++ 这段代码可以在我的PC上编译,但不能在标准C++;98竞争服务器上的编译器,c++,c++98,C++,C++98,我的编译器没有任何错误,我得到了正确的结果。我也尝试过在线C++98编译器,它在那里也同样有效。但是当我在竞赛服务器上检查程序时,它说编译失败了 有人能告诉我如何处理我的编译器或者我的代码有什么问题吗?节目如下: #include <stdio.h> #include <algorithm> using namespace std; class P { public: int t; int l; P();

我的编译器没有任何错误,我得到了正确的结果。我也尝试过在线C++98编译器,它在那里也同样有效。但是当我在竞赛服务器上检查程序时,它说编译失败了

有人能告诉我如何处理我的编译器或者我的代码有什么问题吗?节目如下:

#include <stdio.h>
#include <algorithm>

using namespace std;

class P
{
    public:
        int t;
        int l;
        P();
        P(int t, int l);
        bool operator<(P next);
};

P::P()
{
    this->t = 0;
    this->l = 0;
}

P::P(int x, int y)
{
    this->t = x;
    this->l = y;
}

bool P::operator<(P next)
{
    return this->l > next.l;
}

P a[110];

int main()
{
    int z, n, x, y, tim = 0;
    scanf("%d %d",&z,&n);

    for(int i = 0; i < z; i++)
    {
        scanf("%d %d",&x,&y);
        P b(x,y);
        a[i] = b;
    }   

    sort(a,a + z);
    tim = max(a[0].l,a[0].t);

    for(int i = 1; i <= z; i++)
    {
        tim += a[i - 1].l - a[i].l;
        tim = max(a[i].t,tim);
    }

    printf("%d\n",tim);
}
#包括
#包括
使用名称空间std;
P类
{
公众:
int t;
int l;
P();
P(int t,int l);
布尔运算符端口=0;
这个->l=0;
}
P::P(整数x,整数y)
{
这个->t=x;
这个->l=y;
}
boolp::operator>next.l;
}
pa[110];
int main()
{
intz,n,x,y,tim=0;
scanf(“%d%d”、&z、&n);
对于(int i=0;ifor(int i=1;i您的
运算符
std::max
接受两个
常量T&
参数。不声明比较运算符
常量

bool operator<(const P& next) const;

bool运算符是否从服务器收到任何错误消息?请尝试
stdio.h
->
cstdio
。兼容c++98的编译器不需要提供
stdio.h
,但大多数编译器仍然提供。
bool运算符与您的问题无关,但您可能应该为数组访问添加一些边界检查(
z
)。还要注意,您将访问索引
z
处的数组,该数组将被初始化为零(因为
a
是一个全局变量,如果它是局部变量
a[z]
将是不确定的)。谢谢@MatthieuBrucher!它是“bool”operator@Yksisarvinen参数的副本不是问题(只是不必要),但由于排序函数当时的工作方式,非常量的函数可能会导致编译错误。一些比较对象可能期望参数为常量,并且不能使用常量对象调用非常量成员函数。@Yksisarvinen看到我的答案了。OP是如何在其他任何地方构建它的?这就是问题所在这是一个真正的谜。是的,这是另一个谜。如果他使用的是VS,那么可能是
max
实际上是宏,它不会有这个“问题”确实如此。所以谜团在于OP到底是如何找到这么多提供VS:D的在线服务的。说句公道话,VS的旧版本,新版本在符合标准方面非常出色。