C++宏:如何创建覆盖?
所以我发现需要使用类似 Boost.Extension 让我的应用程序对新模块更加开放。但是当我到达第一个教程时,我发现发现它的语法完全不像我习惯的那样:
// Depending on the compiler and settings,
// it may be necessary to add a specific export
// declaration. The BOOST_EXTENSION_EXPORT_DECL
// adds this if necessary.
void BOOST_EXTENSION_EXPORT_DECL
boost_extension_hello_world(int repetitions) {
for (int i = 0; i < repetitions; ++i) {
std::cout << "Hello World" << std::endl;
}
}
我希望可以编写类似 void function
的东西,而不是 void BOOST_EXTENSION_EXPORT_DECL
它看起来更好,并且因为我有 AS3 背景,对我来说看起来不会那么可怕。
那么如何在您自己的 C++ 文件中而不是在定义它的标头中创建 C++ 宏的覆盖呢?
So I found a need in using something like Boost.Extension to keep my apps more open to new modules. But as soon as I got to first tutorial I found out that its syntax is quite not like I'm used to:
// Depending on the compiler and settings,
// it may be necessary to add a specific export
// declaration. The BOOST_EXTENSION_EXPORT_DECL
// adds this if necessary.
void BOOST_EXTENSION_EXPORT_DECL
boost_extension_hello_world(int repetitions) {
for (int i = 0; i < repetitions; ++i) {
std::cout << "Hello World" << std::endl;
}
}
I want to make it possible to write something like void function
instead of void BOOST_EXTENSION_EXPORT_DECL
it looks better and as i have AS3 background it will not look like something horrible for me.
So how to create an overrite for C++ macro not in header where it was defined but in your own C++ file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在之前编写以下内容:
然后像这样声明该函数:
You could just write the following before:
And then state the function like this:
您可以将
BOOST_EXTENSION_EXPORT_DECL
替换为function
:然后您可以通过以下方式使用它:
但是,如果您的代码包含单词
function
,这可能会导致问题,因为编译器替换所有出现的function
。You can replace
BOOST_EXTENSION_EXPORT_DECL
byfunction
with:Then you can use it by:
But this could cause problems if your code contains the word
function
, because the compiler replace all occurrence offunction
.