2011-03-06 96 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; 
    } 
}