Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ use of class Classname;

I am viewing cocos2dx c++ source code and in it there are many places where they use

class Classname;

e-g in CCNode.h line 43

class CCCamera;

Classname is name of the class they are using and later I dont see any reference to that I never seen this before.

I would like to know what that means.

like image 924
Sam Avatar asked Jul 27 '13 15:07

Sam


People also ask

Why do we use classes in C?

C mostly uses functional/structural programming instead of implementing Object Oriented Programming as in languages like C++ , Java , Python etc. which use classes .

What does class * mean in C++?

class classname* is the return type of the function. class classname is an elaborated type specifier.

What is class in C with example?

C Classes A class consists of an instance type and a class object: An instance type is a struct containing variable members called instance variables and function members called instance methods. A variable of the instance type is called an instance.

What is class and object explain with the help of program?

A class is a user-defined type that describes what a certain type of object will look like. A class description consists of a declaration and a definition. Usually these pieces are split into separate files. An object is a single instance of a class. You can create many objects from the same class type.


1 Answers

This is a forward declaration so that the actual imports occur in the .cpp files instead of the header files. This is a common practice in C++ OOP.

For a good explanation, see this post with a similar question C++ Forward declaration

When you make a forward declaration, you are informing the compiler you intend to use something in advance. The important take aways, as declared in the link above, are that forward declarations break cyclic references and reduce compiler build times.

like image 183
Paul Renton Avatar answered Sep 21 '22 04:09

Paul Renton