Define functions in structs

后端 未结 10 981
南旧
南旧 2020-12-08 08:58

Can we define functions in structs in C programming language?

10条回答
  •  一向
    一向 (楼主)
    2020-12-08 09:48

    No, You cant define functions inside structures in C programs, However if the extension of your file is .cpp (that is not C), you can have member functions like classes however the default modifier of these functions will be 'public'(unlike class).

    Read these links for more information on Structures a good link , another good link, One more good link

    As a convention in C++, Classes are used for storing functions and variables both and Structures are used only for storing information (i.e. data).

提交回复
热议问题