VC warning C4251

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

For example,this

  
  
           
  
  
  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:spa

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

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

  
  
           
  
  
  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. }; 
相關文章
相關標籤/搜索