2014-08-31 144 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