Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Structure prototype?

How do I put a struct in a separate file? I can do it with functions by putting the function prototype in a header file e.g. file.h and the function body in a file like file.cpp and then using the include directive #include "file.h" in the source file with main. Can anybody give a simple example of doing the same thing with a structure like the one below? I'm using dev-c++.

struct person{
  string name;
  double age;
  bool sex;
};

1 Answers

Just declare

struct person;

It is called class forward declaration. In C++, structs are classes with all members public by default.

like image 168
Stefano Borini Avatar answered Jun 03 '26 02:06

Stefano Borini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!