std::vector needs to have dll-interface to be used by clients of class 'X warning

前端 未结 4 1274
长发绾君心
长发绾君心 2020-12-05 06:29

I\'m trying to make my library exportable as a DLL but I\'m getting a lot of these warnings for one specific class that uses std::vector:

template 

        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 07:04

    One fix is relying on dynamic allocation/deallocation of the STL structures. So:

    class EXPORTED ExportedClass
    {
    private:
        std::vector *_integers;
    public:
        ExportedClass()
        {
            _integers = new std::vector();
        }
        ~ExportedClass()
        {
            delete _integers;
        }
    };
    

    won't give any warning and it's more safe in case you are distributing the same binary (the dll) that has to be used with different version of the compiler that may has different versions of the STL. In this way you have 100% guarantee that sizeof(ExportedClass) is always the same.

提交回复
热议问题