2014-08-31 113 views
1
#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 
+0

你在链接什么? – OMGtechy 2014-08-31 22:48:00

+0

告诉我们你是如何建造的。 – 0x499602D2 2014-08-31 22:51:43

回答

2

你已经编译TaroGrid-stub.cc两次,不同的命名对象文件TaroGrid-stub.oTaroGrid.o。这两个对象大多相同(它们可能是相同代码的不同版本)。他们肯定都有main功能。

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

有几个可能的解决方案。

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

感谢您的帮助! – user3520946 2014-09-13 16:25:28