When can I use a forward declaration C/C++?

C++Server Side ProgrammingProgramming

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. 


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.

Published on 28-Feb-2018 06:54:26