将函数传递给函数时,函数不会带1个参数

时间:2016-04-25 06:21:34

标签: c++ visual-c++

我试图将 this 的实例(有问题的实例是GameEngine类)传递到我的PlayerBrain.run方法中,该方法采用对应于这个是。我很好奇在这种情况下会导致抛出这样的错误的原因,特别是当没有run()的替代函数定义或类似的东西时。 PlayerBrain是它自己的类,不是任何东西。因此,没有可能导致问题的替代定义。这是相关代码:

PlayerBrain.h中的所有公共方法

#pragma once
#include "GameEngine.h"
#include "Species.h"
#include "Neuron.h"
#include "Genome.h"
#include "GenePool.h"
#include "Gene.h"
#include <sys/stat.h>
#include <vector>
#include <iostream>
#include <fstream>
#include <Windows.h>
using namespace std;

class PlayerBrain {
private:
    int popSize;
    int stalenessThreshold;
    int timeoutConstant;
    int currentTimeout;
    int maxNodes;
    int farthestDistance;
    bool buttons[6]; // JASON - shoot, left, right, up, down, jump in that order
    GenePool p;

    bool fileExists(string filename);
    bool fitnessAlreadyMeasured();
    void nextGenome();
    void evaluateCurrent(Genome * g);
    void evaluateNetwork(vector<Neuron*> * network, vector<int> inputs);
    void loadPool(string filename);
    double sigmoid(double sum);
    vector<int> getInputs();
    Genome templateGenome();
    void pressAKey();
    void unPressAKey();
    vector<INPUT *> oldbuttons;

public:
    PlayerBrain();
    void intialize();
    void run(GameEngine const *);
    void close();
};

.cpp

中的实际实现
 void PlayerBrain::run(GameEngine const * g) {
    Genome * current = p.getCurrentGenome();
    int xPos = 0;
    int bossLives = 0;
    double fitness;
    double timeoutBonus;

    unPressAKey();

    if ((p.getCurrentFrame() % 5) == 0)
        evaluateCurrent(current);

    pressAKey();

    xPos = g->getXPosAckVar();

    bossLives = g->getBossLivesAckVar();

    if (xPos > farthestDistance) { farthestDistance = xPos; currentTimeout = timeoutConstant; }
    currentTimeout--;
    timeoutBonus = p.getCurrentFrame() / 4;

    if ((currentTimeout + timeoutBonus) <= 0) { 
        fitness = (farthestDistance - (p.getCurrentFrame() / 2)) + 2000 * bossLives; 
        if (fitness == 0) { fitness = -1; }
        current->setFitness(fitness);

        if (fitness > p.getMaxFitness()) { p.setMaxFitness(fitness); }
        p.setCurrentSpecies(0);
        p.setCurrentGenome(0);
        while (fitnessAlreadyMeasured()) { nextGenome(); }
    }
    p.setCurrentFrame(p.getCurrentFrame() + 1);
}

GameEngine.cpp`中的函数调用

while (true)
    {
           ......//irrelevant stuff
            if (tickTimeNow > tickTimeTrigger)
                {
                if (dTimeTrigger > m_PaintTimeTrigger)
                {
                    ....
                    brain->run(this);
                    ....
                }
                else Sleep(1);
            }
            else WaitMessage();
        }
    }

我得到的错误如下: 错误C2660&#39; PlayerBrain :: run&#39;:函数不带1个参数

0 个答案:

没有答案