2012-02-17 97 views
0
/* 
* File: main.cpp 
* Author: c1004527 
* 
* Created on February 15, 2012, 10:25 PM 
*/ 

#include <stdlib.h> 
#include <ctime> 
#include <time.h> 
#include "CardClass.h" 
#include "PlayerClass.h" 

/* 
* 
*/ 
int main(int argc, char** argv) 
{ 
    srand(time(0)); 
    CardClass deck; 
    PlayerClass player[4]; 
    deck.ShuffleCards(); 
    deck.Print(); 
    for(int i = 0; i < DECK_SIZE; i++) 
    { 
     player[i%4].AddACard(deck.DealCards()); 
    } 
    for(int i = 0; i < 4; i++) 
    { 
     player[i].SortCard(); 
    } 
    for(int i = 0; i < 4; i++) 
    { 
     cout << endl << endl 
      << "Player "<< i+1 << endl 
      << player[i]; 
    } 

    return (0); 
} 

的錯誤是:Eclipse的C++錯誤

**** Internal Builder is used for build    
**** g++ -O0 -g3 -Wall -c -fmessage-length=0 -o OLA3\OLA3\main.o ..\OLA3\OLA3\main.cpp 
..\OLA3\OLA3\main.cpp: In function 'int main(int, char**)': 
..\OLA3\OLA3\main.cpp:17:17: error: 'time' was not declared in this scope 
Build error occurred, build is stopped 
Time consumed: 114 ms. 

其他一切編譯完全沒問題但。我使用minGW,它編譯hello world沒有問題。

+3

安置自己的實際代碼。在這一點上,任何人都可以說的唯一事情正是編譯器錯誤所說的:你在沒有首先聲明它的情況下引用一個名爲'time'的變量或函數。我猜你是在說'srand(time(0))',而沒有說'#include '。 – 2012-02-17 21:20:13

回答

1

因爲您已包含<ctime>,time將在std命名空間中定義。
因此,您需要使用完全合格的參考:std::time

這就是這個錯誤是告訴你:

error: 'time' was not declared in this scope

+0

我嘗試使用命名空間標準;而且我仍然遇到錯誤。 – todaroa 2012-02-17 22:00:36