2011-03-06 81 views
0

所以我发现需要使用类似Boost.Extension的东西来让我的应用程序更加开放新模块。但只要我到first tutorial我发现,它的语法非常不喜欢我习惯:C++宏:如何创建一个覆盖?

// 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++宏的overrite,而不是在它被定义的头文件中,而是在您自己的C++文件中?

#define function BOOST_EXTENSION_EXPORT_DECL 

然后你就可以使用它:

+0

LOL @说过人回答的已经回答的问题有,这是完全一样的东西。 – 2011-03-06 20:40:45

+0

@疯狂的埃迪:它的所有关于反馈和解释结束提示和警告假人我。=) – Rella 2011-03-06 21:02:49

回答

0

您可以通过function替换为BOOST_EXTENSION_EXPORT_DECL

void function boost_extension_hello_world(int repetitions) { 
    for (int i = 0; i < repetitions; ++i) { 
    std::cout << "Hello World" << std::endl; 
    } 
} 

但是,如果你的代码中包含单词function这可能会导致问题,因为编译器替换所有发生的function

+0

你的意思是,如果我有一个名为“功能”的变量,它会被替换为BOOST_EXTENSION_EXPORT_DECL? – Rella 2011-03-06 20:47:16

+0

是的,你的变量将被BOOST_EXTENSION_EXPORT_DECL取代。我不建议这样做。对宏使用大写和非通用名称。 – Fox32 2011-03-06 20:49:13

0
#define function BOOST_EXTENSION_EXPORT_DECL 
1

你可以像下面前:

#define function BOOST_EXTENSION_EXPORT_DECL 

然后说出这样的功能:

void function 
boost_extension_hello_world(int repetitions) { 
    for (int i = 0; i < repetitions; ++i) { 
    std::cout << "Hello World" << std::endl; 
    } 
}