0

In MSVC, When I write a class with a std::unordered_map member like below,

class DLLEXPORT TTT
{
    std::unordered_map<int, int> _map;
};

a C4251 warning is given:

warning C4251: 'TTT::_map' : class 'std::unordered_map<_Kty,_Ty>' needs to have dll-interface to be used by clients of class 'TTT'  ...

where DLLEXPORT macro is in normal pattern, which is expand to __declspec(dllexport) or __declspec(dllimport) in the right place.

My question is: if put DLLEXPORT after this class declaration, the C4251 warning is gone, WHY?

class TTT
{
    unordered_map<int, int> _map;
};
class DLLEXPORT TTT;
joong
  • 1
  • 1
    As reference: https://stackoverflow.com/questions/767579/exporting-classes-containing-std-objects-vector-map-etc-from-a-dll Does your approach work? Can you use your class inside of another project as you expect it? – RoQuOTriX Oct 15 '21 at 06:08
  • 1
    No warning because the class does not actually get exported. Not a fix of course. – Hans Passant Oct 15 '21 at 06:44
  • @HansPassant Oh, I think you are right. – joong Nov 09 '21 at 02:38

0 Answers0