C++/CLI 컴파일 오류 - error C4368: mixed types are not supported
C++/CLI 소스 코드를 빌드하는 데 다음과 같은 오류가 발생한다면?
1>------ Build started: Project: ClassLib, Configuration: Release x64 ------
1> TestHash.cpp
1>d:\...[생략]...\TestHash.h(41): error C2353: exception specification is not allowed
1>d:\...[생략]...\TestHash.h(40): error C4368: cannot define 'test2' as a member of managed 'ClassLib::TestHash': mixed types are not supported
2>------ Build started: Project: ConsoleApplication1, Configuration: Release x64 ------
2> ConsoleApplication1 -> D:\...[생략]...\ConsoleApplication1.exe
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
이에 대한 자세한 설명 및 해결책은 다음을 참고하시고.
Some Notes about Mixed Types
; http://blogs.msdn.com/b/branbray/archive/2005/07/20/441099.aspx
간단하게 현재 상황을 풀어보면,
여러분들의 관리 클래스(ref class) 내에서 다음과 같이 C++ 고유의(unmanaged) 타입을 정의했을 때 발생합니다.
#include "CMyCppType.h"
namespace ClassLib
{
public ref class TestClass
{
private:
CMyCppType test;
};
}
해결 방법은, C++ 타입을 그대로 사용할 수 없고 반드시 포인터 참조로 변경해야 합니다. (또는, C++ 타입을 관리 타입으로 변경하거나.)
#include "CMyCppType.h"
namespace ClassLib
{
public ref class TestClass
{
public:
TestClass()
{
test = new CMyCppType();
}
~TestClass()
{
delete test;
}
private:
CMyCppType *test;
};
}
오랜만에, C++/CLI를 만졌더니 하는 것마다
오류가 발생하는군요. ^^
[이 토픽에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]