这个错误是什么
What is this error?
#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.o
和TaroGrid.o
。 这两个对象大多相同(它们可能是同一代码的不同版本(。 它们绝对都具有main
功能。
然后,您将这两个对象传递给链接器,链接器无法确定哪个是真正的main
。
有几种可能的解决方案。
- 删除旧对象文件。
- 不要与
*.o
链接,但实际命名您要使用的特定对象文件。
相关文章:
- 是什么导致了Unity 3D中的"错误线程异常"?
- 在C++中样板"冷/never_inline"错误处理技术的最佳方法是什么?
- 在C++中创建队列 - 什么是 malloc 错误?
- 当我从下面的代码中删除关键字 virtual 时,它可以正常工作,否则会出现错误。在这里"virtual"字的意义是什么?
- 没有可行的过载'='错误,可能导致这种情况的原因是什么?
- Clang 8 带有静态 constexpr 和数组的链接器错误 - 错误是什么以及如何解决它?
- 我遇到了黑客排名中的问题"TWO STRINGS"的三个测试用例的分段错误。原因是什么?
- 导致hash_map错误的原因是什么,如何修复它?
- 当我选择大于 720 的矩阵大小时,程序退出并显示错误代码.可能是什么原因?
- C++中的"expected unqualified-id"错误是什么?
- 谁能告诉我,程序中的错误是什么?该程序仅用于获取文件扩展名
- 是什么导致 glTexSubImage1D() - 加载纹理时在此示例中出现GL_INVALID_VALUE错误?
- 我的代码中针对 NQueens 问题的错误是什么?
- 这在C++是什么类型的错误?
- 出现这种错误的原因是什么"invalid use of non-static data member "
- 这种错误的原因是什么:将"功能"重新定义为不同类型的符号
- CUDA返回值错误35的含义是什么
- 这个错误可能是什么?ANSI C文件
- 是什么导致macOS Mojave上的GoogleTest链接错误
- 这个代码中的错误是什么,每次都会给我分段错误