2010-11-16 55 views
4

給出以下命名空間,我在哪裏把我的declspec(用於dll導出)我想要所有的方法在所述的命名空間導出到DLL?我應該在哪裏放置DECLSPEC作爲命名空間?

namespace AguiText { 
    void drawTextArea(AguiGraphicsManager *g, const AguiFont &font,const AguiRectangle &area, 
     const AguiColor &color, const std::vector<std::string> &lines, 
     AguiHorizontalAlignmentEnum horizontalAlignment, AguiVerticalAlignmentEnum verticalAlignment); 

    void divideText(std::vector<std::string> &words, 
     const std::string &text,const AguiFont &font, int maxWidth = -1); 
    void makeTextLines(const AguiFont &font,const std::vector<std::string> &words, 
     std::vector<std::string> &lineWords, int maxWidth); 
    void pointInTextArea(const AguiFont &font, 
     const AguiRectangle &area, const AguiPoint &point, 
     const std::vector<std::string> &lines, AguiRectangle &retRect, 
     int &retIndex, AguiHorizontalAlignmentEnum horizontalAlignment, AguiVerticalAlignmentEnum verticalAlignment); 

} 

感謝

+0

函數模板必須在頭文件中聲明(除非你打算只針對一組特定的參數對它進行實例化)。所以不需要出口。 – 2010-11-16 23:45:51

+0

@Oil AguiText命名空間怎麼樣? – jmasterx 2010-11-17 00:06:20

回答

5

無需導出一個命名空間。從編譯代碼的角度來看,命名空間是毫無意義的。你不能在代碼中引用它們,它們只是定義範圍。

在名稱修改過程中,名稱空間成爲類/函數名稱的一部分。一旦源文件被編譯,它們就不是獨立的實體。

如果要導出名稱空間的內容,則需要導出這些實體,而不是命名空間本身。

+0

然後,我在哪裏添加AGUI_DECLSPEC,以便將內部函數導出,如drawTextArea? – jmasterx 2010-11-17 00:12:08

+0

我該做什麼 AGUI_DECLSPEC void someThing(); – jmasterx 2010-11-17 00:13:07

+0

函數和類是被導出的實際實體,所以你可以把'__declspec'放在那裏。把命名空間想象成你放在你的函數上的小貼紙。貼紙本身並沒有定義一個實體,他們只是裝飾其他的東西。他們沒有定義可用的對象。他們只是標記。 – 2010-11-17 00:22:04