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;
};
Just declare
struct person;
It is called class forward declaration. In C++, structs are classes with all members public by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With