friend 로 걸린 함수가 extern "C"인데 어떻게 해야하나요.

purewell의 이미지

class myclass
{
  friend void myfunc(int* c);
  // skip...
};

extern "C"
void
myfunc (int* c)
{
  // skip...
}

이렇게 하면 컴파일오류 뜹니다.

아래는 MSDN 검색 결과입니다.

Quote:
Compiler Error C2732

Error Message
linkage specification contradicts earlier specification for 'function'

The function is already declared with a different linkage specifier.

This error can be caused by include files with different linkage specifiers.

Change the extern statements so that the linkages agree.

Example
The following sample generates C2732:

Copy Code
// C2732.cpp
extern void func( void ); // implicit C++ linkage
extern "C" void func( void ); // C2732

friend는 extern과 동일한 효과를 가진다고 하는데,
extern "C++"로 내용을 서술해주면 정상 작동하지만,
문제는 꼬~옥 extern "C"로 노출(아이 부끄...)해야합니다.
(결국 name mangling을 적용하고 싶지 않아서입니다. dll같은 공용객체니깐)

우짜쓸까요.

purewell의 이미지

ㅡ_-) 자문자답입니다.

표준인지는 모르겠지만,

extern "C"
class myclass
{
  friend void myfunc(int c);
  //skip...
}

extern "C"
void myfunc(int c)
{
  //skip...
}

_____________________________
언제나 맑고픈 샘이가...
http://purewell.biz

doldori의 이미지

표준 맞습니다. 다른 방법으로 간단한 wrapper를 쓸 수도 있습니다.

class myclass 
{ 
    friend void realfunc(int c); 
    //skip... 
} ;

void realfunc(int c)
{
    /* ... */
}

extern "C" 
void myfunc(int c) 
{ 
    realfunc(c);
}
purewell의 이미지

> o<)o 감사합니다.

_____________________________
언제나 맑고픈 샘이가...
http://purewell.biz