我有单独的函数从文本文件中读取(取决于它是int,float还是double).我想只有一个带有附加参数的函数(不使用后续的IF语句).有人有想法吗?
以下是我当前功能的形式.
float * read_column_f (char * file, int size_of_col){
...
col = (float*) malloc (height_row * sizeof(float));
... return(col);}
double * read_column_d (char * file, int size_of_col){
...
col = (double*) malloc (height_row * sizeof(double));
... return(col);}
int * read_column_i (char * file, int size_of_col){
...
col = (int*) malloc (height_row * sizeof(int));
... return(col);}
Run Code Online (Sandbox Code Playgroud)
编辑:我想用C++实现它,使用的C风格语法是由于内存偏好.