Home > Backend Development > C++ > body text

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

WBOY
Release: 2023-09-04 19:53:06
forward
1122 people have browsed it

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
};
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template