C++ use of class Classname;
Asked Answered
J

1

5

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.

Jovitta answered 27/7, 2013 at 15:47 Comment(2)
Sounds like a forward declaration. See: When to use forward declaration?Hescock
What @Hescock said. But you really should make a bit more effort to present your question. Uppercasing keywords just can't be done.Subdue
B
7

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.

Blower answered 27/7, 2013 at 15:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.