In a VC dll project, when we export a class which contains a not exported class variable, VC will have a warning(C4251).

For example,

  1. class A  
  2. {  
  3. private:  
  4.     int m_i;  
  5. };  
  6.  
  7. class __declspec(dllexport) B  
  8. {  
  9. private:  
  10.     A m_a;  
  11. }; 

VC will complain:

warning C4251: 'B::m_a' : class 'A' needs to have dll-interface to be used by clients of class 'B'

To work around this problem, we can change the member variable definition like below:

  1. class A  
  2. {  
  3. private:  
  4.     int m_i;  
  5. };  
  6.  
  7.  
  8. class __declspec(dllexport) B  
  9. {  
  10. private:  
  11.     A* m_pa;  
  12. };