Using structure names

In some cases, you may need to use a type before you have actually defined it. As long as you do not use the members, you can declare a type before defining it:

    struct time_of_day;     void print_day(time_of_day time);

This could be declared in a header, where it says that there is a function defined somewhere else that takes a time_of_day record and prints it out. To be able to declare the print_day function, you have to have declared the time_of_day name. The time_of_day struct must be defined somewhere else in your code before the function is defined, otherwise you will get an undefined type error.

There is, however, an exception: a type can hold pointers to instances of the same type before the type is fully declared. ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.