I am working on some legacy code. I have the following data types:
typedef struct {
char *name ;
ColumnType type ;
unsigned pos ; //column position in table
CellData **data ; //ptr to list of cells in column
}Column ;
struct _table {
char name[TABLE_NAME_LEN+1] ;
unsigned int num_rows ;
unsigned int num_cols ;
Column **cols ; //ptr to list of columns
};
struct _table m_
In the source code, there is the following statement:
m_table.cols = new Column*[m_table.num_cols];
I am familiar with new[], but I’m no sure what the multiplication operator is doing there – can any explain?
It’s not multiplication. The symbol
*has many, many completely different meanings in C++, all depending on context.In your case, you’re creating a dynamic array of
Column*, i.e. of pointers toColumn.In other words, you’re saying
new T[N];, whereT = Column*.