C++ Unordered Map Exposed From DLL char

209 views Asked by At

I have a C++ project that compiles as a DLL. I have several classes that possess m_dSurveyStore as member variables. The maps have std::string keys and various custom classes for values. e.g.:

std::unordered_map< std:string , Survey > SurveyStore;

The classes need to be exposed from my DLL for use by other programs (both console C++, but also .Net code). When I use std::string as the map key I get compiler warnings along the lines of "needs to have dll-interface to be used by clients of class". I've read other posts that warn against exposing interfaces that use std types.

Ideally my maps would be private member variables and (I thought) would not be exposed outside the DLL:

class __declspec(dllexport) Project
{
    private:
        SurveyStore m_dSurveyStore;
}

Should I use char * for my map key type if I want to expose the class with these maps as members, or is there a robust way to stick with std::string and only expose the class? If char * is the way to go, please provide the syntax for defining a char * key.

1

There are 1 answers

0
Jake Lin On

You shouldn't use char* as the key, otherwise, you will replay on the pointer address as you key rather than the content of the string. You may need to change you container std::unordered_map to a normal array [].