逻辑运算符导致调用函数的编译时错误

时间:2015-12-19 04:43:55

标签: c++ logical-operators

此问题之前可能已经得到解答,但是搜索并使用谷歌并没有把我带到那里,所以我会问。

我目前正在制作游戏并正在进行碰撞,但是,出于某种原因,似乎每当我尝试编译时,我都会得到ISO C++ forbids comparison between pointer and integer

起初我以为我的语法可能有问题,我检查过,但是找不到任何内容,所以我只是把代码行留给了这个:

if((getMinX() > c->getMinX()) && (getMinX() < c-getMaxX()))

我尝试添加this->或添加括号,但这似乎不起作用,但是,只是在做

if(this->getMinX() > c->getMinX())

似乎和

一样好用
if((5 > 3) && (5 < 10))

我有什么遗失的吗?

这两个对象都是从名为Collideable的类派生而来的,如此

class Collideable
{ public:
    bool collidesWith(Collideable*);
    virtual int getMinX() = 0;
    virtual int getMaxX() = 0;
    virtual int getMinY() = 0;
    virtual int getMaxY() = 0;
};

所有类都正确地覆盖了虚拟方法,导致问题的代码位于bool Collideable::collidesWith(Collideable* c)

根据http://www.cplusplus.com/doc/tutorial/operators/,逻辑运算符返回一个布尔值(这对我来说是有意义的,来自Java)所以导致这个问题的原因是什么?

2 个答案:

答案 0 :(得分:1)

很难知道这是程序中的内容还是简单的转录问题:

第一行写为npm config set registry http://registry.npmjs.org/ ;也许它应该是** * Invocation level: to be executed for each benchmark method execution. * * <p><b>WARNING: HERE BE DRAGONS! THIS IS A SHARP TOOL. * MAKE SURE YOU UNDERSTAND THE REASONING AND THE IMPLICATIONS * OF THE WARNINGS BELOW BEFORE EVEN CONSIDERING USING THIS LEVEL.</b></p> * * <p>This level is only usable for benchmarks taking more than a millisecond * per single {@link Benchmark} method invocation. It is a good idea to validate * the impact for your case on ad-hoc basis as well.</p> * * <p>WARNING #1: Since we have to subtract the setup/teardown costs from * the benchmark time, on this level, we have to timestamp *each* benchmark * invocation. If the benchmarked method is small, then we saturate the * system with timestamp requests, which introduce artificial latency, * throughput, and scalability bottlenecks.</p> * * <p>WARNING #2: Since we measure individual invocation timings with this * level, we probably set ourselves up for (coordinated) omission. That means * the hiccups in measurement can be hidden from timing measurement, and * can introduce surprising results. For example, when we use timings to * understand the benchmark throughput, the omitted timing measurement will * result in lower aggregate time, and fictionally *larger* throughput.</p> * * <p>WARNING #3: In order to maintain the same sharing behavior as other * Levels, we sometimes have to synchronize (arbitrage) the access to * {@link State} objects. Other levels do this outside the measurement, * but at this level, we have to synchronize on *critical path*, further * offsetting the measurement.</p> * * <p>WARNING #4: Current implementation allows the helper method execution * at this Level to overlap with the benchmark invocation itself in order * to simplify arbitrage. That matters in multi-threaded benchmarks, when * one worker thread executing {@link Benchmark} method may observe other * worker thread already calling {@link TearDown} for the same object.</p> */

答案 1 :(得分:1)

您有c-getMaxX()但需要c->getMaxX()c-getMaxX()