Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning C4251: needs to have dll-interface to be used by clients of class [duplicate]

Tags:

c++

Possible Duplicate:
std::vector needs to have dll-interface to be used by clients of class 'X<T> warning

This is my first post in this group.

I am creating a DLL and calling it in the main file of the application. The code compiles fine but I get the following error:

 warning C4251: 'PNCBaseClass::m_vAvailChannelsFromRx' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'PNCBaseClass'
3>          with
3>          [
3>              _Ty=int
3>          ]

My code is as follows:

#define TEST_API __declspec(dllexport)
class TEST_API PNCBaseClass
{
public:
vector<int> m_vAvailChannelsFromRx
};

I have looked up for solutions and tried and failed.

I do not want to disable the warning.

like image 609
chintan s Avatar asked Jun 25 '12 12:06

chintan s


1 Answers

Never keep STL containers as exported class members. Client application may be compiled with different STL version than yours, with undefined runtime behavior. In your case, it is easy to replace vector<int> member with pointer vector<int>*. Initialize it in the class constructor, and release in the class destructor.

like image 180
Alex F Avatar answered Nov 01 '22 08:11

Alex F