功能定义无法识别

时间:2015-10-31 04:50:57

标签: c++

#include <vector>
#include <iostream>
using namespace std;

typedef vector<bool> row;
typedef vector<row> matrix;


//Corner functions
int population_tlc(int x, int y, matrix& grid)
{
    int popu;
    for(int yi = y+1; yi >= y; y--)
    {
        for(int xi = x+1; xi >= x; x--)
        {
           if (grid[yi][xi] == true)
           {
               popu++;
           }
        }
    }
    return popu;
}

int population_trc(int x, int y, matrix& grid)
{
    int popu;
    for(int yi = y+1; yi >= y; y--)
    {
        for(int xi = x-1; xi <= x; x++)
        {
           if (grid[yi][xi] == true)
           {
               popu++;
           }
        }
    }
    return popu;
}

int population_blc(int x, int y, matrix& grid)
{
    int popu;
    for(int yi = y-1; yi <= y; y++)
    {
        for(int xi = x-1; xi >= x; x--)
        {
           if (grid[yi][xi] == true)
           {
               popu++;
           }
        }
    }
    return popu;
}


int population_brc(int x, int y, matrix& grid)
{
    int popu;
    for(int yi = y-1; yi <= y; y++)
    {
        for(int xi = x-1; xi <= x; x++)
        {
           if (grid[yi][xi] == true)
           {
               popu++;
           }
        }
    }
    return popu;
}
//Edge functions
int population_left(int x, int y, matrix& grid)
{
    int popu;
    for(int yi = y-1; yi <= y+1; y++)
    {
        for(int xi = x; xi<= x+1; x++)
        {
            if(xi == x && yi == y)
            {
                continue;
            }
            if (grid[yi][xi] == true)
           {
               popu++;
           }
    }
    return popu;
}


int population_top(int x, int y, matrix& grid)
{
    int popu;
    for(int yi = y; yi <= y+1; y++)
    {
        for(int xi = x-1; xi<= x+1; x++)
        {
            if(xi == x && yi == y)
            {
                continue;
            }
            if (grid[yi][xi] == true)
           {
               popu++;
           }
        }
    }
    return popu;
}

int population_right(int x, int y, matrix& grid)
{
    int popu;
    for(int yi = y-1; yi <= y+1; y++)
    {
        for(int xi = x-1; xi<= x; x++)
        {
            if(xi == x && yi == y)
            {
                continue;
            }
            if (grid[yi][xi] == true)
           {
               popu++;
           }
        }
    }
    return popu;

}

我正在尝试制作一个模仿康威生活游戏的程序。这些函数采用x和y坐标以及main中网格的引用。这些函数检查网格中x和y坐标点的周围环境,并确定它应该是真(活)还是假(死)。问题是在最后两个函数中,即使我定义了函数,IDE仍然会提示我;。我还有一个充满所有功能原型的头部保护。

#include <vector>
#include <iostream>
using namespace std;

typedef vector<bool> row;
typedef vector<row> matrix;

int population_tlc(int x, int y, matrix& grid);
int population_trc(int x, int y, matrix& grid);
int population_blc(int x, int y, matrix& grid);
int population_brc(int x, int y, matrix& grid);
int population_left(int x, int y, matrix& grid);
int population_top(int x, int y, matrix& grid);
int population_right(int x, int y, matrix& grid);
int population_bottom(int x, int y, matrix& grid);

我的问题是如何让它“实现”它是一个函数定义和一个不完整的函数原型。提前谢谢

1 个答案:

答案 0 :(得分:1)

此功能中缺少listB

}

因此请将其替换为:

int population_left(int x, int y, matrix& grid)
{
    int popu;
    for(int yi = y-1; yi <= y+1; y++)
    {
        for(int xi = x; xi<= x+1; x++)
        {
            if(xi == x && yi == y)
            {
                continue;
            }
            if (grid[yi][xi] == true)
           {
               popu++;
           }
    }
    return popu;
}

您可以找到一些编辑器或IDE,可能会突出显示这种拼写错误;)(例如,emacs)