2014-04-10 21 views
0

我需要幫助創建標準庫C++地圖。我必須使用的代碼看起來像這樣。如何使用具有多類模板的地圖

template<class Key, class Type> 


    public: 
     STLMap(){ 
     //constructor goes here 
     } 

我知道如何使用只有一個類模板來製作一張地圖,但我不知道怎麼有兩個做。在這種情況下,鍵和類型是我需要與地圖一起使用的關鍵和類型。

在此先感謝。

回答

0

您使用KeyType作爲實際類型,並且當使用模板時,將使用實際類型。 std::map<Key, Type>對於STLMap<int, char>將變成std::map<int, char>

template<class Key, class Type> 
class STLMap 
{ 
    public: 
    STLMap() 
    { 
    } 

    private: 
    std::map<Key, Type> _map; 
} 
+0

感謝您的信息。我有一個問題是,現在我得到「錯誤:'地圖'在命名空間'標準'不命名類型」響鈴? – user2865370

+0

我已經想出了我的第二個問題;我忘了#include 。 – user2865370

相關問題