Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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++ 架构x86_64的未定义符号:错误_C++ - Fatal编程技术网

C++ 架构x86_64的未定义符号:错误

C++ 架构x86_64的未定义符号:错误,c++,C++,所以我在另一个类中创建了一个helper函数,但它没有编译 这就是错误所在 Undefined symbols for architecture x86_64: "move(sc2::Unit const*, sc2::Unit const*)", referenced from: Ihurt_Multi_Unit_Bot::OnStep() in battle_simulator.cc.o 我称之为移动函数 virtual void OnStep() { Uni

所以我在另一个类中创建了一个helper函数,但它没有编译

这就是错误所在

Undefined symbols for architecture x86_64:
  "move(sc2::Unit const*, sc2::Unit const*)", referenced from:
      Ihurt_Multi_Unit_Bot::OnStep() in battle_simulator.cc.o
我称之为移动函数

virtual void OnStep()
{   
    Units alive = Observation()->GetUnits();
    for (int i = 0; i<alive.size(); i++)
    {
        if (alive[i]->unit_type == 9)
            enemy = alive[i];

        if ((Observation()->GetGameLoop() % 2) == 0)
        {
            if (alive[i]->unit_type == 48) 
            {
                move(alive[i], enemy);
            }

        }
函数的类

void move(const Unit* unit, const Unit* enemy);

class commands : public Agent 
{
    commands() = default;
    void move(const Unit* unit, const Unit* enemy)
    { 
        Point2D moveto;
        double path = Query()->PathingDistance(unit->pos, enemy->pos);

        if (path < Observation()->GetUnitTypeData()[enemy->unit_type].weapons.front().range) 
        {
            moveto = getBestMove(unit->pos, enemy->pos);
            Actions()->UnitCommand(unit, ABILITY_ID::MOVE, moveto);
        }
    }

如果我们将代码简化为一个最小的示例,那么问题可能会更明显:

void move();

class commands
{
public:
   void move()
   {
   }
};

int main()
{
    move();
}
您已经声明并正在调用一个自由函数move,但只在commands类中定义了一个方法move

根据你想要达到的目标,有很多方法可以解决这个问题。最好是删除move函数并调用该方法:

class commands
{
public:
   void move()
   {
   }
};

int main()
{
    commands cmds;
    cmds.move();
}

移动功能的实现在哪里?我只能看到commands::move方法的一个实现?您已经用相同的名称和几乎相同的签名声明了两个不同的函数,但只定义了一个。您编写了调用另一个的代码。这是你第一次尝试使用方法吗?你是说该方法是朋友吗?在onstep函数中,onstep函数调用move。你知道move指的是什么功能吗?函数定义在哪里?我对C++是新的,但我对编程并不陌生。我是如何声明两个不同的函数的。我只需要在另一个文件中使用一个移动函数。谢谢,就是这样