# Deriving from TGNumberEntry gives compiler errors unresolved symbol

**URL:** <https://root-forum.cern.ch/t/deriving-from-tgnumberentry-gives-compiler-errors-unresolved-symbol/43167>\
**Category:** Newbie\
**Created:** [January 19, 2021, 6:33pm UTC](https://root-forum.cern.ch/t/deriving-from-tgnumberentry-gives-compiler-errors-unresolved-symbol/43167 "2021-01-19T18:33:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmahf](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bmahf](https://root-forum.cern.ch/u/bmahf)\
**Post date:** [January 19, 2021, 6:33pm UTC](https://root-forum.cern.ch/t/deriving-from-tgnumberentry-gives-compiler-errors-unresolved-symbol/43167/1 "2021-01-19T18:33:52Z")

</div>

I am working on a code base using Root 5.28, building with VS2008. I am trying to inherit from some GUI controls in the application to extend their functionalities. I have started with TGNumberEntry and TGNumberEntryField, changing them so that the TGNumberEntry or TGNumberEntryField owns a unique ID which can later be queried for. I have also overridden TGNumberEntryField::SetNumber() so that after calling the parent class’s version, I can do some other work. There is more functionality to be added but this is the only functionality I added so far, and it is shown in the example code below. I have included the header file in the cpp file for the MyMainWindow class, and added member pointer variables, both of type TGNumberEntryField. The project compiles without a problem, but I get the following linker errors:

```
error LNK2001: unresolved external symbol "public: virtual void __thiscall MyNumberEntryField::ShowMembers(class TMemberInspector &)" (?ShowMembers@MyNumberEntryField@@UAEXAAVTMemberInspector@@@Z)
error LNK2001: unresolved external symbol "public: virtual void __thiscall MyNumberEntryField::Streamer(class TBuffer &)" (?Streamer@MyNumberEntryField@@UAEXAAVTBuffer@@@Z)
error LNK2019: unresolved external symbol "public: static class TClass * __cdecl MyNumberEntryField::Class(void)" (?Class@MyNumberEntryField@@SAPAVTClass@@XZ) referenced in function "public: virtual class TClass *__thiscall MyNumberEntryField::IsA(void)const " (?IsA@MyNumberEntryField@@UBEPAVTClass@@XZ)
error LNK2001: unresolved external symbol "public: virtual void __thiscall MyNumberEntry::ShowMembers(class TMemberInspector &)" (?ShowMembers@MyNumberEntry@@UAEXAAVTMemberInspector@@@Z)
error LNK2001: unresolved external symbol "public: virtual void __thiscall MyNumberEntry::Streamer(class TBuffer &)" (?Streamer@MyNumberEntry@@UAEXAAVTBuffer@@@Z)
error LNK2019: unresolved external symbol "public: static class TClass * __cdecl MyNumberEntry::Class(void)" (?Class@MyNumberEntry@@SAPAVTClass@@XZ) referenced in function "public: virtual class TClass *__thiscall MyNumberEntry::IsA(void)const " (?IsA@MyNumberEntry@@UBEPAVTClass@@XZ)
error LNK2019: unresolved external symbol "class ROOT::TGenericClassInfo * __cdecl ROOT::GenerateInitInstance(class MyNumberEntryField const *)" (?GenerateInitInstance@ROOT@@YAPAVTGenericClassInfo@1@PBVMyNumberEntryField@@@Z) referenced in function "void__cdecl ROOT::`dynamic initializer for 'R__dummyintdefault6''(void)" (??__ER__dummyintdefault6@ROOT@@YAXXZ)
error LNK2019: unresolved external symbol "class ROOT::TGenericClassInfo * __cdecl ROOT::GenerateInitInstance(class MyNumberEntry const *)" (?GenerateInitInstance@ROOT@@YAPAVTGenericClassInfo@1@PBVMyNumberEntry@@@Z) referenced in function "void__cdecl ROOT::`dynamic initializer for 'R__dummyintdefault7''(void)" (??__ER__dummyintdefault7@ROOT@@YAXXZ)

```

I have tried everything I can think of, looking down into Root code, but haven’t been able to figure this issue out. I am not yet well enough versed in how ClassDef stuff works in Root, so I am certain I am missing some small thing. While I continue digging, I am posting this to see if anyone has an idea of what I should look at in order to fix the issue. Thanks for any help. The code for my new classes (given as MyNumberEntry and MyNumberEntryField) is shown below:

MyNumberEntry.h:

```
#ifndef MY_NUMBER_ENTRY_H
#define MY_NUMBER_ENTRY_H

#include "Rtypes.h"
#include "Windows4Root.h"
#include "TGNumberEntry.h"

class MyNumberEntryField : public TGNumberEntryField
{
public:
    MyNumberEntryField(const TGWindow *p, Int_t id,
                      Double_t val, GContext_t norm,
                      FontStruct_t font = GetDefaultFontStruct(),
                      UInt_t option = kSunkenFrame | kDoubleBorder,
                      Pixel_t back = GetWhitePixel());
    MyNumberEntryField(const TGWindow *parent = 0,
                      Int_t id = -1, Double_t val = 0,
                      EStyle style = kNESReal,
                      EAttribute attr = kNEAAnyNumber,
                      ELimit limits = kNELNoLimits,
                      Double_t min = 0, Double_t max = 1);
    ~MyNumberEntryField() { }
    
    virtual void SetNumber(Double_t val);
    void SetObjID(int id) { m_iObjId = id; }
    int GetObjID() { return m_iObjId; }

private:
    int m_iObjId;

public:
   ClassDef(MyNumberEntryField,0) // Entry field widget for several numeric formats (wraps TGNumberEntryField)
};

class MyNumberEntry : public TGNumberEntry
{
public:
    MyNumberEntry(const TGWindow *parent = 0, Double_t val = 0,
                 Int_t digitwidth = 5, Int_t id = -1, 
                 EStyle style = kNESReal,
                 EAttribute attr = kNEAAnyNumber,
                 ELimit limits = kNELNoLimits,
                 Double_t min = 0, Double_t max = 1);
    ~MyNumberEntry() { }

    void SetObjID(int id) { fNumericEntry->SetObjID(id); }
    int GetObjID() { return fNumericEntry->GetObjID(); }

    MyNumberEntryField *GetNumberEntry() const {
        // Get the number entry field
        return fNumericEntry;
    }

protected:
   MyNumberEntryField *fNumericEntry; // Number text entry field

public:
   ClassDef(MyNumberEntry,0) // Entry field widget for several numeric formats (wraps TGNumberEntry)
};

#endif // MY_NUMBER_ENTRY_H

```

MyNumberEntry.cpp:

```
#include "MyNumberEntry.h"

ClassImp(MyNumberEntryField);
ClassImp(MyNumberEntry);

/ *******************************************
/* class MyNumberEntryField
/ ******************************************* /

MyNumberEntryField::MyNumberEntryField(const TGWindow * p, Int_t id,
                                       Double_t val, GContext_t norm,
                                       FontStruct_t font, UInt_t option,
                                       ULong_t back)
    : TGNumberEntryField(p, id, val, norm, font, option, back) { }

MyNumberEntryField::MyNumberEntryField(const TGWindow * parent,
                                       Int_t id, Double_t val,
                                       EStyle style, EAttribute attr,
                                       ELimit limits, Double_t min,
                                       Double_t max)
    : TGNumberEntryField(parent, id, val, style, attr, limits, min, max) { }

MyNumberEntryField::~MyNumberEntryField()
{
}

void MyNumberEntryField::SetNumber(Double_t val)
{
    // set the number in the base class
    TGNumberEntryField::SetNumber(val);
    // then do my stuff
    DoMyStuff(); // function not shown
}
    
/ *******************************************
/* class MyNumberEntry
/ ******************************************* /

MyNumberEntry::MyNumberEntry(const TGWindow *parent, Double_t val,
                 Int_t digitwidth, Int_t id, 
                 EStyle style,
                 EAttribute attr,
                 ELimit limits,
                 Double_t min, Double_t max)
    : TGNumberEntry(parent, val, digitwidth, id, style, attr, limits, min, max)
{
}

MyNumberEntry::~MyNumberEntry()
{
}

```

* * *

_ROOT Version:_ 5.28  
_Platform:_ Window 7  
_Compiler:_ VS2008

* * *

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [January 19, 2021, 9:15pm UTC](https://root-forum.cern.ch/t/deriving-from-tgnumberentry-gives-compiler-errors-unresolved-symbol/43167/2 "2021-01-19T21:15:36Z")

</div>

Did you generate a dictionary for that class? (It is required for any class with a ClassDef macro unless you use ClassDefInline).

---

<div class="post-metadata">

**Author:** ![bmahf](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bmahf](https://root-forum.cern.ch/u/bmahf)\
**Post date:** [January 20, 2021, 2:04pm UTC](https://root-forum.cern.ch/t/deriving-from-tgnumberentry-gives-compiler-errors-unresolved-symbol/43167/3 "2021-01-20T14:04:06Z")

</div>

I hadn’t. I created a dictionary and now it works. Thanks. I am still trying to learn the ins and outs of Root. I had looked up the ClassDef and ClassImp, but didn’t find any useful information. Thanks. Now I can move forward with this.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [January 20, 2021, 2:29pm UTC](https://root-forum.cern.ch/t/deriving-from-tgnumberentry-gives-compiler-errors-unresolved-symbol/43167/4 "2021-01-20T14:29:59Z")

</div>

Note that ClassImp is vestigial and no longer needed.

---

<div class="post-metadata">

**Author:** ![bmahf](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bmahf](https://root-forum.cern.ch/u/bmahf)\
**Post date:** [January 22, 2021, 4:05pm UTC](https://root-forum.cern.ch/t/deriving-from-tgnumberentry-gives-compiler-errors-unresolved-symbol/43167/5 "2021-01-22T16:05:30Z")

</div>

Is that the case for 5.28 though? ClassImpl being vestigial I mean.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [January 22, 2021, 6:19pm UTC](https://root-forum.cern.ch/t/deriving-from-tgnumberentry-gives-compiler-errors-unresolved-symbol/43167/6 "2021-01-22T18:19:35Z")

</div>

Same-ish. It is helpful only if you (still) rely/use THtml to generate documentation.

---

<div class="post-metadata">

**Author:** ![bmahf](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bmahf](https://root-forum.cern.ch/u/bmahf)\
**Post date:** [January 24, 2021, 7:07pm UTC](https://root-forum.cern.ch/t/deriving-from-tgnumberentry-gives-compiler-errors-unresolved-symbol/43167/7 "2021-01-24T19:07:23Z")

</div>

Not sure if this should be a new topic. I’ll post it here since it seems directly related, and hope that someone will let me know if it should be. But I’m just wondering. I have gotten passed the original problem by creating the necessary dictionary file and compiling it into my build. Now I’m trying to create a Connect to my object to replace the Connect that was made to the original TGNumberEntry object. I have updated the header file as followings:

```
class MyNumberEntry : public TGNumberEntry
{
public:
	...
	Constructor/destructor decl
	...
	
	virtual void ValueSet(Long_t val); //*SIGNAL* - this is the new declaration

public:
	ClassDef(MyNumberEntry,0) // Entry field widget for several numeric formats (extends TGNumberEntry)
};

```

And have updated my cpp file as:

```
...
	Constructor/destructor def
...

void MyNumberEntry::ValueSet(Long_t val) //*SIGNAL* - this is the new definition
{
	Emit("ValueSet(Long_t)", val);
}

```

Basically I have just made a copy of the ValueSet() signal as it is in TGNumberEntry. This is because when I tried to just connect to the Connect() call, just as it was before inheriting the class, hoping that it would connect to TGNumberEntry::ValueSet(), it crashes the application with “0xC0000005: Access violation reading location 0x00000014”. The stack says it happened calling IsA() inside the ClassDef() macro, which calls Class() and crashes. As stated I have the necessary dictionary being created, using the line:

(ROOTSYS)\bin\rootcint -f (InputDir)MyNumberEntry\_dictionary.cpp -c (InputDir)MyNumberEntry.h "(InputDir)LinkDef\_MyNumberEntry.h"

where the LinkDef\_MyNumberEntry.h file is as follows:

```
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

// classes inherited from TGNumberEntry and TGNumberEntryField
#pragma link C++ class MyNumberEntry+;
#pragma link C++ class MyNumberEntryField+;

```

When I add MyNumberEntry::ValueSet(Long\_t val) to my inherited class, I get the same crash. I really am not sure what I am missing this time.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [January 25, 2021, 5:40pm UTC](https://root-forum.cern.ch/t/deriving-from-tgnumberentry-gives-compiler-errors-unresolved-symbol/43167/8 "2021-01-25T17:40:17Z")

</div>

Can you run the failing example with valgrind:

```auto
valgrind --suppressions=$ROOTSYS/etc/valgrind-root.supp ....

```

this might tell us what is going wrong.
