C++/모두의코드

8-1 장

twoweeks-within 2025. 2. 9. 21:30
Cell*** data_table;
Table::Table(int max_row_size, int max_col_size)
    : max_row_size(max_row_size), max_col_size(max_col_size) {
  data_table = new Cell**[max_row_size];
  for (int i = 0; i < max_row_size; i++) {
    data_table[i] = new Cell*[max_col_size];
    for (int j = 0; j < max_col_size; j++) {
      data_table[i][j] = NULL;
    }
  }
}

 

 

 

 

1. data_table 이라는 3중 포인터

     

2.

 data_table = new Cell**[max_row_size];
 // Cell* 들을 저장하는 배열
 // 각 배열의 시작주소들을 저장

 

     > data_table 은 Cell** 타입

     > max_row_size 만큼의 row(열) 배열생성

3.

  for (int i = 0; i < max_row_size; i++) {
    data_table[i] = new Cell*[max_col_size];
    for (int j = 0; j < max_col_size; j++) {
      data_table[i][j] = NULL;
    }
  }

 

 > 한 개의 row (열) 에 j개만큼의 col (행) 배열생성

 

  > data_table[i] 는 Cell* 을 저장하는 배열

     > i번째에 max_col_size 만큼의 배열 생성

 

  > data_table[i][j] 는 각 배열의 값 저장

 

>>>>>

data_table (Cell** 타입)

------------------------------------------ > Cell** [0]
:  [0][0]  :    [1][0]     :             :   > Cell* [0]   , Cell*[1]  , Cell* [2] 
:  [0][1]  :    [1][1]     :             :     > Cell[0][0], Cell[1][0], ..
------------------------------------------     > Cell[0][1], Cell[1][1], ..
------------------------------------------ > Cell** [1]
:          :               :             :   > Cell* [0], Cell* [1],
:          :               :             :
------- ----------------------------------
------------------------------------------ > Cell** [2]
:          :               :             : 
:          :               :             :
------- ----------------------------------

 

>

Cell::Cell(string data, int x, int y, Table* table)
    : data(data), x(x), y(y), table(table) {}

  각 요소들은 이러한 Cell 객체의 주소를 저장 !

 

순수가상함수 : 함수 = 0; 인 형태

ex)

virtual string print_table() = 0;

  > 추상 클래스 > 객체 생성 X 

     > 상속 받아서 자식쪽에서 오버라이딩

 

'C++ > 모두의코드' 카테고리의 다른 글

7장  (0) 2025.02.04
6장  (0) 2025.02.02
5장 // 5.3 뒷부분은 복습때  (0) 2025.02.01
4장 이어서..  (0) 2025.01.31
3장, 4장  (0) 2025.01.30