관리되는 래퍼 클래스를 friend로 선언하기

  • Post author:
  • Post category:
  • Post comments:2 Comments
  • Post last modified:November 11, 2008
// native.h
class NativeClass
{
#ifdef __cplusplus_cli
	friend ref class ManagedClass;
#endif

private:
	int PrivateMethod();
};

// managed.h
ref class ManagedClass
{
private:
	int PrivateMethod()
	{
		return m_NativeObj->PrivateMethod();
	}

	NativeClass* m_NativeObj;
}

핵심은 __cplusplus_cli 키워드다. 이 키워드가 없어도 되지 않냐? 이렇게 생각하기 쉬운데 그렇지 않다. 네이티브 컴파일러는 ref 키워드를 모른다. 그래서 네이티브 컴파일러가 이 헤더 파일을 참조할 때 반드시 __cplusplus_cli 키워드가 있어야 한다. 그렇지 않으면 컴파일 오류가 난다.

Author Details
Kubernetes, DevSecOps, AWS, 클라우드 보안, 클라우드 비용관리, SaaS 의 활용과 내재화 등 소프트웨어 개발 전반에 도움이 필요하다면 도움을 요청하세요. 지인이라면 가볍게 도와드리겠습니다. 전문적인 도움이 필요하다면 저의 현업에 방해가 되지 않는 선에서 협의가능합니다.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
방준영
15 years ago

그 밑의 ManagedClass도 통째로 감싸줘야겠죠.^^

최재훈
15 years ago

각각의 클래스가 별도 파일에 정의됐다는 이야기를 빼먹었군요. 만약 한 파일에 넣는다면 그렇게 해야죠. ^^