What are the reasons for casting a void pointer?

后端 未结 3 1410
梦如初夏
梦如初夏 2021-01-18 06:41

I\'m learning C++ from scratch, and as such I don\'t have an expert understanding of C. In C++, you can\'t cast a void pointer to whatever, and I understand the reasons behi

3条回答
  •  独厮守ぢ
    2021-01-18 07:39

    One reason: if you use sort to sort an array of structs, and you have a comparison function for the two structs, you'll need to cast the void pointers to pointers to the structs to access members of the struct.

提交回复
热议问题