简体   繁体   English

在 C++ 中定义类时使用 #define 宏

[英]Use of a #define Macro while defining a class in C++

#define EXPORT_SPEC 

class EXPORT_SPEC CBoard {
.......
}

What is the use or purpose of EXPORT_SPEC in the above class definition.上述类定义中 EXPORT_SPEC 的用途或目的是什么。

how this class definition is different from normal class definition.这个类定义与普通类定义有何不同。

Ur help is highly appreciated.非常感谢您的帮助。

None is the answer to your question.没有是你问题的答案。 The macro has no value so it will be "removed" by the pre-processor.宏没有任何价值,因此它将被预处理器“删除”。 As el.pescado said, macros like this are used to build libraries (as opposed to stand-alone apps).正如 el.pescado 所说,像这样的宏用于构建库(与独立应用程序相反)。

The point of the #define use is to specify a non-changing value. #define 使用的要点是指定一个不变的值。 In the case you are mentioning, you would be able to set the name of a class according to some preference set in that #define call.在您提到的情况下,您将能够根据该 #define 调用中设置的某些首选项设置类的名称。 Eg例如

#define CLASS_NAME "Employee"

class CLASS_NAME something {
...
}

In this case, you can change the class / object name by the #define call.在这种情况下,您可以通过 #define 调用更改类/对象名称。 I don't know if there is too much use in that, or at least not too much that I can think of.我不知道这是否有太多用处,或者至少不是我能想到的太多。

This question was also addressed here .此问题也已在此处解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM