how to initialize a static map

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rajesh1978
    New Member
    • Sep 2006
    • 3

    #1

    how to initialize a static map

    Hi I have the below class

    I want to initialize the static map which takes string , string
    But when I compile it is giving me an erro like constant expression is required.

    class FunctionCaller{
    static std::map<std::s tring,std::stri ng> functionMap;
    public:
    FunctionCaller( ){}

    };
    std::map<std::s tring,std::stri ng>FunctionCall er::functionMap["function1"] = "obj1";


    please suggest
    Thanks
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You intialize the map by:
    [code=cpp]
    std::map<std::s tring,std::stri ng>FunctionCall er::functionMap ;
    [/code]

    Since this is a private static variable you will need to use a class method to insert objects in the map.

    Remember, you can only insert pair objects.

    Comment

    Working...