LNK2019 error with implemented virtual functions

Owen Ransen 541 Reputation points
2021-12-06T11:20:25.563+00:00

I'm getting a LNK2019 error with implemented virtual functions.

In the base class the functions are declared as virtual with =0 to make them pure virtual.

In the base class constructor I call these pure virtual functions, assuming that the base class will call the appropriate derived class function.

As I write that I realize that maybe the base class has no idea which derived function to call and tries to link with its own pure virtual function. which of course it cannot find.

CClassifier::CClassifier(CComPtr<ComponentDefinition>& pAsmCompDef,
                         CComPtr<Document>& pGenAsmDoc,
                         const CString& kcsClassName)
    : m_kcsSapCode(GetCodiceSAPFromInventorDoc(pGenAsmDoc))
    , m_kcsClassName (kcsClassName)
{
    // Here the base class is trying to call pure virtual functions
    //  Doing this gives me a NLK2019 error
    InitTagIdDescList () ;
    InitAttValPairList (pAsmCompDef,pGenAsmDoc) ;
}

If I do the call in the derived class, I do not get the link error:

CClassifierCct3D::CClassifierCct3D(CComPtr<ComponentDefinition>& pCompDef,
                                   CComPtr<Document>& pGenAsmDoc,
                                   const CString& kcsClassName)
    : CClassifier (pCompDef,pGenAsmDoc,kcsClassName)
{
    // links ok...
    InitTagIdDescList () ;
    InitAttValPairList (pCompDef,pGenAsmDoc) ;
}

Is my reasoning about why I got the error correct?

If so why doesn't the compiler tell me I cannot call pure virtual functions?

Where am I? Who am I?

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
784 questions
0 comments No comments
{count} votes

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.