Reputation: 15392
In the headers of my Objective-C classes, I use @class MyClassName
to be able to use the MyClassName
object in a defined class.
In Objective-C, there's a difference between @class MyClassName
and #import MyClassName.h
?
Does such a difference exist in C++?
The C++ equivalent of #import "MyClassName.h"
is #include "MyClassName.h"
.
What is the C++ equivalent of Objective-C @class MyClassName
?
Upvotes: 3
Views: 822
Reputation: 8109
The C++ equivalent of #import "MyClassName.h
" is not #include "MyClassName.h"
"#import" also prevent cyclic inclusion of files for which in c++ we normally do
#ifdef __abc.h__
#define __abc.h__
//actual code
#endif
Upvotes: 1
Reputation: 9590
yes there is such distinction in C++ too. In C++ it is called forward declaration. You forward declare a class like:
class ClassName;
Just to add extra info, forward declaration is used when you are using a class before it is declared. The compiler will be bit lenient and wont throw error but it still need the full class declaration later.
Upvotes: 1
Reputation: 170819
Forward declaration in c++ looks similar - just remove '@' from obj-c variant:
class MyClassName;
Upvotes: 8