1

The problem related to the Warning C4251 'X' needs to have dll-interface to be used by clients of class 'Y' is explained very well here: How can I use Standard Library (STL) classes in my dll interface or ABI?

The reason why it isn't good idea to have lets say std::string as member in a class which is exported from a library is clear for me and it makes sense. However, I don't really understand why it isn't a problem if I use an std::string as an argument type or as a return type?

class DllPort SampleClass
{
private:
    std::string privateMember;  // Warning C4251

public:
    std::string publicMember;   // Warning C4251

    std::string publicFunction1();          // compiler says it is OK
    void publicFunction2(std::string value);// compiler says it is OK
};

I use Visual Studio 2015.

Community
  • 1
  • 1
Zoltan Tirinda
  • 769
  • 8
  • 25
  • I think the reason is that `std::string` is an explicit specialization of `std::basic_string`. Hence, it is not a class template any more. – R Sahu Mar 16 '16 at 20:28
  • That applies to all four cases alike though, @RSahu. That said, I think that the answer in the mentioned SO post spreads quite some FUD in addition to the useful info. Take a look at e.g. Boost to get an idea how to do it correctly. It takes a bit more to set up, but then you don't have to compromise your interface for dynamic linking. – Ulrich Eckhardt Mar 16 '16 at 21:23

0 Answers0