Microsoft MVP성태의 닷넷 이야기
VC++: 13. VS.NET 2005 VC++ 컴파일러 에러 : cannot instantiate abstract class [링크 복사], [링크+제목 복사],
조회: 24686
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

아... 천하의 정성태가. ^^; 논리 버그도 아닌, 컴파일러 에러에 이렇게 시간을 허비했다니... 부끄러울 따름입니다.

어느 날... 기존 구현된 COM 개체의 인터페이스와 그 메서드들이 제공하는 기능을 구현해야 할 일이 생겼습니다.
그런데, 컴파일 단계에서 다음과 같은 오류가 발생하는 것이었습니다.

e:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcom.h(2578) : error C2259: 'ATL::CComObject<Base>' : cannot instantiate abstract class
        with
        [
            Base=CXApplication
        ]
        due to following members:
        'HRESULT IXApplication2::IsDestinationReachable(BSTR,VARIANT_BOOL *)' : is abstract
        d:\workshop\infopath\DxDocsViewer\DxDocsViewer.h(7595) : see declaration of 'IXApplication2::IsDestinationReachable'
        e:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcom.h(2570) : while compiling class template member function 'HRESULT ATL::CComObject<Base>::CreateInstance(ATL::CComObject<Base> **) throw()'
        with
        [
            Base=CXApplication
        ]
        d:\workshop\infopath\DxDocsViewer\DocsServer.h(500) : see reference to class template instantiation 'ATL::CComObject<Base>' being compiled
        with
        [
            Base=CXApplication
        ]

다들 익히 아시는 거지요? ^^ 자... 찬찬히 살펴보겠습니다.
우선, IDL 파일에는 다음과 같은 인터페이스를 정의했습니다.


[
  object,
  uuid(096CD6BB-0786-11D1-95FA-0080C78EE3BB),
  dual,
  nonextensible,
  helpstring("IXApplication2 Interface"),
  pointer_default(unique)
]
interface IXApplication2 : IXApplication
{

    [id(0x00000010)] HRESULT IsDestinationReachable([in] BSTR bstrDestination, [out, retval] VARIANT_BOOL *pfReachable);

};

그리고는, 해당 인터페이스를 구현하는 ATL COM 개체의 헤더 파일에는 다음과 같이 정의했습니다.

   STDMETHOD( IsDestinationReachable )(BSTR bstrDestination, VARIANT_BOOL *pfReachable)
    {
        return E_NOTIMPL;
    }

그런데... 그와 같은 컴파일 오류가 발생한 것입니다. 여러분들은 어떻게 생각하십니까? ^^; 제가 뭐 잘못한 거라도 있는 걸까요?

정말이지... 컴파일 에러에서 고심한다고,,, 챙피해서 주변에 도움을 구할 수도 없고... ^^;

요리 저리 해보다가... ^^; 결국 문제가 밝혀지긴 했습니다.
제가 기능 구현을 위해 포함시켜 두었던
#include <sensapi.h>
가 문제였지요.

바로 그 헤더 파일에 동일한 이름의 메서드가 선언되었던 것입니다. 물론... 메서드 선언만이었다면 그런 문제는 발생하지 않았을 것입니다. 즉,
BOOL IsDestinationReachable( LPCSTR lpszDestination, LPQOCINFO lpQOCInfo);
위의 선언이라면 컴파일 에러가 발생하지 않았을 텐데.

윈도우 헤더 파일의 특기인 Ansi / Unicode API 지원을 위해 정의해 두었던 매크로 들과 겹쳐서 문제가 되었던 것입니다.
#ifdef UNICODE
#define IsDestinationReachable IsDestinationReachableW
#else
#define IsDestinationReachable IsDestinationReachableA
#endif // UNICODE
보통 위와 같은 트릭을 많이 쓰죠.

위의 매크로 영향으로 인해서, 제가 정의했던 메서든 다음과 같이 치환이 되었고,

   STDMETHOD( IsDestinationReachableA )(BSTR bstrDestination, VARIANT_BOOL *pfReachable)
    {
        return E_NOTIMPL;
    }
결국, IDL 에서 정의한 인터페이스 명세대로 IsDestinationReachable 메서드를 구현하지 않았으므로 컴파일러는 그와 같은 오류를 발생시킨 것입니다.









[최초 등록일: ]
[최종 수정일: 1/29/2005]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 31  32  [33]  34  35  36  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
13148정성태10/26/202215325오류 유형: 824. msbuild 에러 - error NETSDK1005: Assets file '...\project.assets.json' doesn't have a target for 'net5.0'. Ensure that restore has run and that you have included 'net5.0' in the TargetFramew
13147정성태10/25/202214515오류 유형: 823. Visual Studio 2022 - Unable to attach to CoreCLR. The debugger's protocol is incompatible with the debuggee.
13146정성태10/24/202215915.NET Framework: 2060. C# - Java의 Xmx와 유사한 힙 메모리 최댓값 제어 옵션 HeapHardLimit
13145정성태10/21/202215932오류 유형: 822. db2 - Password validation for user db2inst1 failed with rc = -2146500508
13144정성태10/20/202216226.NET Framework: 2059. ClrMD를 이용해 윈도우 환경의 메모리 덤프로부터 닷넷 모듈을 추출하는 방법파일 다운로드1
13143정성태10/19/202216985오류 유형: 821. windbg/sos - Error code - 0x000021BE
13142정성태10/18/202222018도서: 시작하세요! C# 12 프로그래밍
13141정성태10/17/202217361.NET Framework: 2058. [in,out] 배열을 C#에서 C/C++로 넘기는 방법 - 세 번째 이야기파일 다운로드1
13140정성태10/11/202217208C/C++: 159. C/C++ - 리눅스 환경에서 u16string 문자열을 출력하는 방법 [2]
13139정성태10/9/202214798.NET Framework: 2057. 리눅스 환경의 .NET Core 3/5+ 메모리 덤프로부터 모든 닷넷 모듈을 추출하는 방법파일 다운로드1
13138정성태10/8/202217708.NET Framework: 2056. C# - await 비동기 호출을 기대한 메서드가 동기로 호출되었을 때의 부작용 [1]
13137정성태10/8/202215812.NET Framework: 2055. 리눅스 환경의 .NET Core 3/5+ 메모리 덤프로부터 닷넷 모듈을 추출하는 방법
13136정성태10/7/202215908.NET Framework: 2054. .NET Core/5+ SDK 설치 없이 dotnet-dump 사용하는 방법
13135정성태10/5/202216698.NET Framework: 2053. 리눅스 환경의 .NET Core 3/5+ 메모리 덤프를 분석하는 방법 - 두 번째 이야기 [1]
13134정성태10/4/202213131오류 유형: 820. There is a problem with AMD Radeon RX 5600 XT device. For more information, search for 'graphics device driver error code 31'
13133정성태10/4/202214672Windows: 211. Windows - (commit이 아닌) reserved 메모리 사용량 확인 방법 [1]
13132정성태10/3/202214692스크립트: 42. 파이썬 - latexify-py 패키지 소개 - 함수를 mathjax 식으로 표현
13131정성태10/3/202218405.NET Framework: 2052. C# - Windows Forms의 데이터 바인딩 지원(DataBinding, DataSource) [2]파일 다운로드1
13130정성태9/28/202214528.NET Framework: 2051. .NET Core/5+ - 에러 로깅을 위한 Middleware가 동작하지 않는 경우파일 다운로드1
13129정성태9/27/202215168.NET Framework: 2050. .NET Core를 IIS에서 호스팅하는 경우 .NET Framework CLR이 함께 로드되는 환경
13128정성태9/23/202218092C/C++: 158. Visual C++ - IDL 구문 중 "unsigned long"을 인식하지 못하는 #import [1]파일 다운로드1
13127정성태9/22/202216495Windows: 210. WSL에 systemd 도입
13126정성태9/15/202216775.NET Framework: 2049. C# 11 - 정적 메서드에 대한 delegate 처리 시 cache 적용
13125정성태9/14/202217080.NET Framework: 2048. C# 11 - 구조체 필드의 자동 초기화(auto-default structs)
13124정성태9/13/202217262.NET Framework: 2047. Golang, Python, C#에서의 CRC32 사용
13123정성태9/8/202217194.NET Framework: 2046. C# 11 - 멤버(속성/필드)에 지정할 수 있는 required 예약어 추가
... 31  32  [33]  34  35  36  37  38  39  40  41  42  43  44  45  ...