6

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.

Community
  • 1
  • 1
chintan s
  • 6,170
  • 16
  • 53
  • 86

1 Answers1

10

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.

Alex F
  • 42,307
  • 41
  • 144
  • 212
  • Thanks Alex. I am not an expert on coding. I tried what you said but I still get the warning. So in the constructor, I did m_vAvailChannelsFromRx.push_back(0) and in the destructor, I just cleared the variable. – chintan s Jun 25 '12 at 13:36
  • Well, what I did is the following in the constructor y = new std::vector() and delete y in the destructor. – chintan s Jun 25 '12 at 13:45