
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
When can I use a forward declaration C/C++?
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
Class Person; void myFunc(Person p1) { // ... } Class Person { // Class definition here };
So in this case when compiler encounters myFunc, it'll know that its 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 in C/C++?
- When to use i++ or ++i in C++?
- What happens when a function is called before its declaration in C?
- What is a smart pointer and when should I use it in C++?
- When to use extern in C/C++
- Structure declaration in C language
- When to use inline function and when not to use it in C/C++?
- When to use C over C++, and C++ over C?
- When to use tuples in C#?
- When to use references vs. pointers in C/C++
- What are forward declarations in C++?
- forward list::cend() in C++ STL
- When to use virtual destructors in C++?
- Forward list assign() function in C++ STL
- Can I Win in C++

Advertisements