2013-03-25 2 views
0

Visual Studio 2005 C++ 코드를 Visual Studio 2010으로 마이그레이션합니다. 불행히도 VS2005에서는 std :: string에 오류가 발생하지만 VS2005에서는이 오류가 발생하지 않았습니다. 여기 std :: string은 Visual Studio 2010에서 컴파일러 경고를 표시합니다.

는 코드 예제와 같이

#include<string> 

typedef std::string String 

class __declspec(dllexport) SomeClass 
{ 
public: 
    String somevariable; // compiler warning here. Please see below for the compiler warning. 

    void SomeFunction(String sName); // No compiler errors or warning here 
}; 

컴파일러 경고 :

error C2220: warning treated as error - no 'object' file generated 
warning C4251: 'SomeClass::somevariable' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'SomeClass' 

with 
[ 
    _Elem=char, 
    _Traits=std::char_traits<char>, 
    _Ax=std::allocator<char> 
] 

나에게이 문제에 대한 솔루션을 제공하기 위해 도와주세요.

+0

http://stackoverflow.com/questions/5661738/common-practice-in-dealing-with-warning-c4251-class-needs-to-have-dll-inter – Arun

+1

PIMPL 관용구를 사용 가능한 해결책이 here -http : //stackoverflow.com/questions/767579/exporting-classes-containing-std-objects-vector-map-etc-from-a-dll – Arun

답변

0

나는 Arun이 처음 제출 한 링크를 읽고 이해하는 것이 좋습니다. 그런 다음, 서로 다른 컴파일러 (C++의 재난을 대비하는 방법)를 사용하지 않는다고 합리적으로 확신 할 수 있다면 경고를 단순히 해제하거나 무시하면됩니다.

은 BTW :

  • 나는 몇 가지 코드를 VS2005에서 같은 경고를 얻을.
  • 동작이 일관성이 없다는 것이 맞습니다. 함수와 membervariable은 진단을 트리거하거나 둘 다 트리거하지 않아야합니다.
관련 문제