question

JohnCTX-6479 avatar image
0 Votes"
JohnCTX-6479 asked Viorel-1 commented

Can enumerated variables relate to built-in functions?

Can users enumerate variables to functions?
If it is possible then can anyone provide me some examples?

c++
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Can you provide examples of what you are asking?

0 Votes 0 ·

Here would be the returning data type and variable with its function, for example:

enum File_Functions { file_read, file_write };

int file_read();
int file_write();

Can those returning variables with their designated built-in functions work?

0 Votes 0 ·

Maybe you need a function pointer, an array of function pointers, or a structure that contains function pointers, depending on other details about your needs.


0 Votes 0 ·

1 Answer

GuidoFranzke avatar image
1 Vote"
GuidoFranzke answered

Hello,
no, it's not possible in the way you want to do. enum doesn't collect function names.
Read this: enum
You can use the enum for named identifiers so that your code gets more readable. And use an if-statement to call the corresponding function.
For example:

 enum eFileFunctions { FILE_READ = 1, FILE_WRITE };
 switch (ifunc)
 {
 case FILE_READ:  iRet = file_read(); break;
 case FILE_WRITE:  iRet = file_write(); break;
 default: cout << "unknown function" << endl;
 }


Regards, Guido



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.