Can C++ struct have member functions?

前端 未结 6 1855
孤街浪徒
孤街浪徒 2021-01-30 13:10

I was pretty confused about the difference between struct and class as I seemed to see them used for pretty much the same things. I googled the differences and the only answer I

6条回答
  •  無奈伤痛
    2021-01-30 13:43

    It seems to me that just because something is allowed by a language does NOT mean it is a good idea. Although technically a C++ struct can contain functions, I don't think the original intent of the struct data type was to contain functions. Was it not the main purpose of introducing a Class type to support defining the data and the logic that acts on the data in a close knit relationship, thus promoting healthier interfaces to the data?

提交回复
热议问题