Can C++ struct have member functions?

前端 未结 6 1740
孤街浪徒
孤街浪徒 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:49

    I am currently working on a project, and I just realized that my struct needs to be able to provide a comparison operators in order for the sorted list that contains it to be able to do the sorting. So it makes sense to have operator overloading in a struct. That's the only legitimate reason to have a struct with methods.

提交回复
热议问题