I’m not very experienced in cpp (used to work in python).
I have the following problem:
1) I have a main class A (a window) and the methods m_A1 and m_A2
2) I have a little class B (a dialog) with a callback m_B1
3) the class B is instantiated and destroyed inside of m_A1
4) from the callback m_B1 I need to call m_A2
I tried to give to B reference to the instance of A (with ‘this’) but this solution that worked in python here doesn’t.
I tried to declare the class B inside of A to have the methods of A accessible inside of B but I can’t understand how to write the code of the methods of B, writing for example the class constructor of B would be
A::B::A::B() but gives syntax errors.
Here’s some code:
class Centrino
{
public:
Centrino();
virtual ~Centrino();
Gtk::Window *mp_window;
protected:
...
bool on_window_key_press(GdkEventKey *event);
void io_process_incoming_command(char *in_str_complete);
...
};
class DebugDialog : public Gtk::Dialog
{
public:
DebugDialog(const char *title, Gtk::Window& parent, bool modal);
virtual ~DebugDialog() {};
protected:
void on_button_send_clicked();
...
};
void Centrino::io_process_incoming_command(char *in_str_complete)
{
...
}
bool Centrino::on_window_key_press(GdkEventKey *event_key)
{
if(event_key->state & GDK_CONTROL_MASK)
{
if((event_key->keyval == GDK_KEY_d) || (event_key->keyval == GDK_KEY_D))
{
DebugDialog dialog("Debug Dialog", *mp_window, true);
int response = dialog.run();
}
}
...
}
void DebugDialog::on_button_send_clicked()
{
Glib::ustring entry_content = m_entry.get_text();
io_process_incoming_command(entry_content.c_str());
}
Centrino is the class that I called A, DebugDialog is the class that I called B.
From DebugDialog:: on_button_send_clicked() I need to call Centrino:: io_process_incoming_command().
The scope of the class DebugDialog instance is inside of Centrino:: on_window_key_press().
Can anybody point me to an example? Thanks in advance.
Add a Centrino reference in DebugDialog attributes and provide it in DebugDialog contructor. Declare Centrino::io_process_incoming_command() method public and invoke it from DebugDialog::on_button_send_clicked() method: