Home >Backend Development >C++ >In C/C++, when can I use forward declarations?

In C/C++, when can I use forward declarations?

WBOY
WBOYforward
2023-09-04 19:53:061146browse

In C/C++, when can I use forward declarations?

In C, a forward declaration lets the code following the declaration know that a class exists It's called "people". When the compiler sees these names used, it is satisfied. Later linkers The class definition will be found.

Sample Code

Class Person;
void myFunc(Person p1) {
   // ...
}
Class Person {
   // Class definition here
};

So in this case when the compiler encounters myFunc it will know that it will encounter this class somewhere in the code. This can be used in situations where code using the class Place/include before the code containing the class definition.

The above is the detailed content of In C/C++, when can I use forward declarations?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete