这个错误是什么

What is this error?

本文关键字:是什么 错误      更新时间:2023-10-16
#include <iostream>
#include <vector>
#include <string>
using namespace std;

class TaroGrid{
public:
    int getNumber(vector<string> grid)
    {
        int n = grid.size(), max = 0, count = 1;
        for (int j = 0; j < n; j++)
        {
            for (int i = 1; i < n; i++)
            {
                if (grid[i][j] == grid[i - 1][j]) count++;
                else count = 1;
                if (count > max) max = count;
            }
        }
        return max;
    };
};

int main()
{
    TaroGrid test;
    vector<string> cool;
    int t = test.getNumber(cool);
    cout << "The largest number of cells Taro can choose is:  " << t <<endl;
    return 0;
}

您的代码未编译:

链接错误:

TaroGrid-stub.o:In function `main':
   TaroGrid-stub.cc:(.text.startup+0x0): multiple definition of `main'
TaroGrid.o:
   TaroGrid-stub.cc:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status

您已经编译了两次TaroGrid-stub.cc,以不同的方式命名对象文件TaroGrid-stub.oTaroGrid.o。 这两个对象大多相同(它们可能是同一代码的不同版本(。 它们绝对都具有main功能。

然后,您将这两个对象传递给链接器,链接器无法确定哪个是真正的main

有几种可能的解决方案。

  1. 删除旧对象文件。
  2. 不要与*.o链接,但实际命名您要使用的特定对象文件。