To investigate another problem (free() error at program end), I tried to override the destructor of the FLTK Fl_Input class. The code compiles but fails in the link with an undefined reference.
I have looked at a number of examples but am not understanding the answers enough to know what I need to change to fix the problem. While this program will not reproduce the free() problem, if the Fl_Input objects (and Fl_Output objects) produce messages, I can determine which one is being freed invalidly.
#include <FL/Fl.H>
#include <FL/Fl_Input.H>
#include <iostream>
class Fl_Inputc:public Fl_Input
{
public:
Fl_Inputc();
Fl_Inputc(int left, int up, int width, int height, const char* label=0);
~Fl_Inputc()
{
// std::cout << " Inputc destroyed " << std::endl;
};
};
Fl_Inputc input1( 90, 10, 180, 20, " Input : ");
int main(int argc, char **argv) {
return Fl::run();
}
I expected a clean compile and link with a modified destructor and everything else inherited but instead got:
cbc:~/Projects/fltk/Tut/Potthast$ fltk-config --compile 07example4b.cxx
g++ -I/usr/include/cairo -I/usr/include/glib-2.0
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include
-I/usr/include/pixman-1 -I/usr/include/freetype2
-I/usr/include/libpng12 -I/usr/include/freetype2
-I/usr/include/cairo -I/usr/include/glib-2.0
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include
-I/usr/include/pixman-1 -I/usr/include/freetype2
-I/usr/include/libpng12 -g -O2 -fvisibility-inlines-hidden
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT
-o '07example4b' '07example4b.cxx' -Wl,-Bsymbolic-functions -lfltk
-lX11
/tmp/cc423i4F.o: In function `__static_initialization_and_destruction_0':
/Projects/fltk/Tut/Potthast/07example4b.cxx:17: undefined reference
to `Fl_Inputc::Fl_Inputc(int, int, int, int, char const*)'
collect2: error: ld returned 1 exit status
To resolve this using the suggestion from @alter igel I used a using statement to get the constructors from the base class.
#include <FL/Fl.H>
#include <FL/Fl_Input.H>
#include <iostream>
class Fl_Inputc:public Fl_Input
{
public:
using Fl_Input::Fl_Input;
~Fl_Inputc()
{
std::cout << " Inputc destroyed " << std::endl;
};
};
Fl_Input input0( 90, 10, 180, 20, " Input0: ");
Fl_Inputc input1( 90, 40, 180, 20, " Input1: ");
int main(int argc, char **argv) {
return Fl::run();
}