![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
When can I use a forward declaration in C/C++?
In C++ the forward declaration lets the code following the declaration know that there is are classes with the name Person. This satisfies the compiler when it sees these names used. Later the linker will find the definition of the classes.
Example Code
Class Person; void myFunc(Person p1) { // ... } Class Person { // Class definition here };
So in this case when compiler encounters myFunc, it'll know that it is going to encounter this class somewhere down in the code. This can be used in cases where code using the class is placed/included before the code containing the class definition.
Advertisements