与Objective C“@class MyClassName”等价的c++是什么?

时间:2022-09-24 19:59:59

In the headers of my Objective-C classes, I use @class MyClassName to be able to use the MyClassName object in a defined class.

在我的Objective-C类的头中,我使用@class MyClassName在定义的类中使用MyClassName对象。

In Objective-C, there's a difference between @class MyClassName and #import MyClassName.h?

在Objective-C中,@class MyClassName和#import MyClassName.h有区别吗?

Does such a difference exist in C++?

在c++中存在这样的差异吗?

The C++ equivalent of #import "MyClassName.h" is #include "MyClassName.h".

与#import“classname”等价的c++。h”# include“MyClassName.h”。

What is the C++ equivalent of Objective-C @class MyClassName ?

什么是c++的Objective-C @class MyClassName ?

3 个解决方案

#1


8  

Forward declaration in c++ looks similar - just remove '@' from obj-c variant:

在c++中的Forward声明看起来很相似——只需从object -c变体中删除“@”:

class MyClassName;

#2


1  

yes there is such distinction in C++ too. In C++ it is called forward declaration. You forward declare a class like:

是的,c++也有这样的区别。在c++中,它被称为forward declaration。您向前申报的课程如下:

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.

为了添加额外的信息,在声明之前使用一个类时使用forward声明。编译器将会有点宽容,不会抛出错误,但它仍然需要稍后的完整类声明。

#3


1  

The C++ equivalent of #import "MyClassName.h" is not #include "MyClassName.h"

与#import“classname”等价的c++。h不是#include "MyClassName.h"

"#import" also prevent cyclic inclusion of files for which in c++ we normally do

“#import”还可以防止我们在c++中经常遇到的循环包含文件

#ifdef __abc.h__
#define __abc.h__

//actual code


#endif

#1


8  

Forward declaration in c++ looks similar - just remove '@' from obj-c variant:

在c++中的Forward声明看起来很相似——只需从object -c变体中删除“@”:

class MyClassName;

#2


1  

yes there is such distinction in C++ too. In C++ it is called forward declaration. You forward declare a class like:

是的,c++也有这样的区别。在c++中,它被称为forward declaration。您向前申报的课程如下:

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.

为了添加额外的信息,在声明之前使用一个类时使用forward声明。编译器将会有点宽容,不会抛出错误,但它仍然需要稍后的完整类声明。

#3


1  

The C++ equivalent of #import "MyClassName.h" is not #include "MyClassName.h"

与#import“classname”等价的c++。h不是#include "MyClassName.h"

"#import" also prevent cyclic inclusion of files for which in c++ we normally do

“#import”还可以防止我们在c++中经常遇到的循环包含文件

#ifdef __abc.h__
#define __abc.h__

//actual code


#endif