Hi this is my first post, and I'm kind of a beginner (re-learning) so i'm sure my code is full of bad coding practices etc.... anyway i've been making a little bit of code that is a window using gtkmm that you can quicky add buttons and bind member functions of other classes too and i'm toootally stumped by this bug (although no doubt its something stupid i've done). if anybody can point me in the right direction it would make me VERY happy.
the bug :-
g++ ./build/control_panel.o ./build/test.o -o build/control `pkg-config gtkmm-2.4 --libs`
./build/test.o: In function `Test::run()':
test.cpp.text._ZN4Test3runEv[Test::run()]+0x5f): undefined reference to `void ControlPanel::add_button<Test, Test>(Glib::ustring, Test*, void (Test::*)())'
here's my code
control_panel.h
Code:
#ifndef GUARD_CONTROL_PANEL_H
#define GUARD_CONTROL_PANEL_H
#include <gtkmm.h>
class ControlPanel : public Gtk::Window {
public:
ControlPanel();
ControlPanel(Glib::ustring caption);
virtual ~ControlPanel();
template<class S, class T>
void add_button(Glib::ustring caption, S *object, void (T::*member_function_ptr)());
protected:
Gtk::VBox widget_box;
};
#endif
control_panel.cpp
Code:
#include "control_panel.h"
ControlPanel::ControlPanel() {
set_title("control panel");
add(widget_box);
show_all_children();
}
ControlPanel::ControlPanel(Glib::ustring caption) {
set_title(caption);
add(widget_box);
show_all_children();
}
ControlPanel::~ControlPanel() {
}
// create button connected to a member function
template<class S, class T>
void ControlPanel::add_button(Glib::ustring caption, S *object, void (T::*member_function_ptr)()) {
// create new button
Gtk::Button *button = new Gtk::Button(caption);
widget_box.pack_start(*button);
// connect member function to button.
button->signal_clicked().connect(sigc::mem_fun(*object, member_function_ptr));
}
test.cpp
Code:
#include "control_panel.h"
#include <iostream>
#include <gtkmm.h>
class Test {
public:
Test() { control = new ControlPanel(); }
~Test() { delete control;}
void show() { std::cout << "coooool" << std::endl; }
void run() {
Glib::ustring s = "Button";
control->add_button(s, this, &Test::show);
}
protected:
ControlPanel *control;
};
int main(int argc, char *argv[]) {
Test test;
test.run();
return 1;
}