C++, how to declare a struct in a header file

后端 未结 7 1511
暖寄归人
暖寄归人 2021-01-30 14:40

I\'ve been trying to include a structure called \"student\" in a student.h file, but I\'m not quite sure how to do it.

My student.h file code c

7条回答
  •  无人共我
    2021-01-30 14:48

    Your student.h file only forward declares a struct named "Student", it does not define one. This is sufficient if you only refer to it through reference or pointer. However, as soon as you try to use it (including creating one) you will need the full definition of the structure.

    In short, move your struct Student { ... }; into the .h file and use the .cpp file for implementation of member functions (which it has none so you don't need a .cpp file).

提交回复
热议问题