Demonstrates defining a struct in a separate .h file and using it in main.cpp.
| File | Purpose |
|---|---|
Student.h |
Struct definition (the "blueprint") |
main.cpp |
Uses the struct |
- Header guards (
#ifndef,#define,#endif) prevent multiple inclusion - Include with quotes for local headers:
#include "Student.h" - Initializer list must match struct member order:
{ id, name, gpa }
g++ main.cpp -o main
./mainNote: You don't compile .h files directly — they're included into .cpp files.