2010-01-31 6 views
0

클래스를 만들었으며 구문 오류없이 컴파일했지만 해결되지 않은 외부 기호가 6 개 있습니까?해결되지 않은 외부 오류

클래스 :

struct CELL { 
private: 
    static bool haslife; 
static int x; 
static int y; 
public: 

    static bool has_life() 
    { 
     return haslife; 
    } 

    static void set_coords(int xcoord, int ycoord) 
    { 
     x = xcoord; 
     y = ycoord; 
    } 
    static void get_coords(int &xcoord, int &ycoord) 
    { 
     xcoord = x; 
     ycoord = y; 
    } 


}; 


class cell_grid { 
private: 
static int cell_size; 
static int cell_count_x; 
static int cell_count_y; 
CELL **cell; 
public: 
    cell_grid(); 
    cell_grid(unsigned int width,unsigned int height, unsigned int cellsize) 
    { 

     //set size based on cellsize 

     this->cell_size = cellsize; 
     this->cell_count_x = floor((double)width/this->cell_size); 
     this->cell_count_y = floor((double)height/this->cell_size); 


     this->cell = new CELL*[this->cell_count_y]; 

     for(int i = 0; i < this->cell_count_y; i++) 
     { 
      cell[i] = new CELL[this->cell_count_x]; 
     } 

     for(int y = 0; y < this->cell_count_y; ++y) 
     { 
      for(int x = 0; x < this->cell_count_x; ++x) 
      { 
       int cur_x = x * this->cell_size; 
       int cur_y = y * this->cell_size; 
       this->cell[x][y].set_coords(cur_x,cur_y); 
      } 
     } 

    } //end of constructor 

    static int get_cell_size() 
    { 
     return cell_size; 
    } 
static void render(BITMAP *buff) 
{ 
    circlefill(buff,70,70,60,makecol(27,37,0)); 

} 


}; 

주요

int main() 
{ 
    start_allegro(); 
    cell_grid *grid = new cell_grid(scr_w,scr_h,10); 
    grid->render(buffer); 


     //Main Loop 
    while (!done && !key[KEY_ESC]) //until 'X' pressed or ESC 
{ 
//***** Start Main Code Here ***** 
    while (speed_counter > 0) 
    { 



       //render the buffer to the screen 

      blit(
      buffer, 
      screen, 
      0,0,0,0, 
      scr_w, 
      scr_h); 

      clear_bitmap(buffer); 

     speed_counter --; 
    } 
//***** End Main Code Here ***** 
rest(1); //Normalize cpu usage 
} 
    return 0; 
} 
END_OF_MAIN() 

감사

+0

해결할 수없는 기호는 무엇입니까? –

답변

4

정적으로 클래스의 모든 변수를 정의하지 마십시오.
데이터 멤버를 정적으로 정의하면 인스턴스가 하나만 있다는 것을 의미합니다. 이것은 당신이 여기서하고 싶은 것 같지 않습니다.
대신

private: 
    static bool haslife; 
    static int x; 
    static int y; 

쓰기의 : 당신이 정적 멤버를 정의 할 때

private: 
    bool haslife; 
    int x; 
    int y; 

는 더욱 더, 당신은 CPP 파일에 다시 정의하고 값으로 초기화해야합니다. 당신이 그렇게하고있는 것처럼 보이지 않아 링커 오류가 발생합니다.

또한 다음에 무언가를 게시 할 때 단순히 사실을 말하면서 실제로 질문해야합니다.

+0

좋은 점은 정적 인 것처럼 보이지 않습니다. –

+0

예. 기본 cell_grid 생성자도 누락되었습니다. –

+0

감사합니다. 과거에는 컴파일러가 wernt에 대해 도청했기 때문에 모든 것을 정적으로 만들었지 만 클래스 인스턴스를 만들 때는 필요하지 않습니다. – jmasterx

관련 문제