
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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.
- Related Articles
- When can I use a forward declaration C/C++?
- When to use i++ or ++i in C++?
- What happens when a function is called before its declaration in C?
- When can we use a JSONStringer in Java?
- What is a smart pointer and when should I use it in C++?
- When should I use a composite index in MySQL?
- When Should I use Selenium Grid?
- Structure declaration in C language
- When should I use the keyword ‘this’ in a Java class?
- When should I use a semicolon after curly braces in JavaScript?
- When should I use MySQL compressed protocol?
- When can we use Synchronized blocks in Java?
- When to use inline function and when not to use it in C/C++?
- When should I use an Inline script and when to use external JavaScript file?
- When to use extern in C/C++

Advertisements