문제

C ++ 2005 및 MFC를 사용하여 C ++ 프로그램을 컴파일하려고 시도하고 있습니다. 슬프게도 컴파일하는 동안 다음 오류가 발생합니다.

Error 2 error LNK2005: "public: virtual __thiscall CMemDC::~CMemDC(void)" (??1CMemDC@@UAE@XZ) already defined in CMemDCImpl.obj Project\Project\Project\uafxcwd.lib(afxglobals.obj) Project.
.

CMEMDCIMPL에는 클래스 cmemdcimpl 클래스의 정의 및 구현이있는 * .cpp 파일의 정의를 포함하는 헤더 파일이 있습니다.이 오류를 해결하도록 도와주세요.

도움이 되었습니까?

해결책

You mention that you CMemDCImpl is defined in a cpp file. However, it also seems to be defined in uafxcwd.lib (a library you apparently use). I can think of two possibilities for this error:

  1. You're including the cpp of the library you're attempting to use. Usually, when you use a precompiled library, you only need to reference the header file in your own source file and the library at link time. Is it possible that you included the source .cpp files of the library in your own project? If this is the case, simply remove the source .cpp files from your project.
  2. You're defining a class of your own that has the same name as the one you're referencing in the library and you have a name clash. The preferred method to fix this issue is to encapsulate the class you defined yourself in a namespace:

.

namespace Foo
{
    class CMemDC
    {
        // ...
    };
}

// Usage:
Foo::CMemDC myMemDC;

다른 팁

Without the actual code, we can only guess. Most likely you have done one of these:

  • Implemented CMemDC::~CMemDC() {} twice, maybe a copy-paste that you didn't rename to CMemDCImpl::~CMemDCImpl()
  • Implemented CMemDC::~CMemDC() in a header file after CMemDC class definition instead of in the class definition

Solution I use : rename the well known and well used CMemDC class in something as CMemDc

because Microsoft crushed it and Keith or ourselves have not copyrighted it ?!?

in vs2k10 Microsoft dared to crush the name of the CMemDC class of Keith, with some shit.

Yesterday born Microsoft guys : this it's one of the most popular classes that everyone uses since 1997! Gross! Shame on you, Microsoft !

CMemDc - memory DC

// Author: Keith Rule

// Email: keithr@europa.com

// Copyright 1996-1997, Keith Rule

Thank You Keith ! Those "new" and "catastrophic" guys of "the after-Gates" want us to change every "CMemDC" in every sources we have.. What a shame

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top