开发者

Can I put a function inside a struct?

开发者 https://www.devze.com 2023-01-03 00:17 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消