A fun usage of macro, define

xiaoxiao2021-03-06  42

In order not to forget, write a little bit.

Data file data.tbl: Data_TBL (John, 1, 2, 3), DATA_TBL (Mike, 3, 2, 1), Data_TBL (Lily, 4, 2, 4),

In AA.H:

#undefine data_tbl # define data_tbl (name, x, y, z) Nameenum {#include "data.tbl" name_max,};

In AA.CPP:

#undefine data_tbl # define data_tbl (name, x, y, z) {x, y, z} int gdata [] = {#include "data.tbl"};

This is rough, the code is not compiled. This allows you to set the data together for easy modification. The only unhappy is that every time you modify the data file, it is equivalent to modifying .h file, compiling, 嘻嘻. There are some other usages, I will think about it later.

转载请注明原文地址:https://www.9cbs.com/read-45235.html

New Post(0)