Can I put a function inside a struct?
Maybe I use inline functions...
There are any way to archieve it, without using function pointers?开发者_如何学运维Thanks in advance.
Not in C. You can in C++. A struct is just a class with all members being public by default in that language.
No, structure supports only a pointer to a function.
Not in C. But you can in C++.
No
The only way I can think of is similar to this one (with function pointers).
to complement all other answers, i would add that a, in C, a structure is only for storing data: a function is not data, so it cannot be stored into a structure.
however, as pcent pointed out, a pointer to a function is a type of data and can be stored in a structure.
精彩评论