Combobox addlistener

I want to add a listerer to see if the combobox content has changed ( for selecting a midi input ). I’ve the following code, but when debugging (VC++) it pop’s up juceasyncupdater.cpp

ComboBox* comboBox1;
ComboBoxListener* test;

comboBox1 = new ComboBox (T("combo"));
addAndMakeVisible (comboBox1);
comboBox1->setBounds (10, 75, 200, 24);		

How do I need change the code to check if the listerer works ?

//void comboBoxChanged(ComboBox *combobox) //{ if(combobox==comboBox1) // { DBG (T("test")); // } //} [/code]

Er yes, well if you pass it an uninitialised pointer as its listener, then I wouldn’t be too surprised if it crashes when it tries to call it!

How can I initialise a pointer ? I’m really new in c++ programming, I’ve some trouble understanding pointers.

I thought I had initialised it with :

It might be really obvious, but I hope you would give me a hint.

A good en clear resource on understanding the use of pointers would also be helpfull.

When you do

ComboBoxListener *test;

that’s just creates a pointer that points nowhere (NULL depending on a compiler i guess). Anyway it’s “nothing”. You need to initialize it with

ComboBoxListener *test = new ComboBoxListener();

but that’s propably not something you want in this case, you propably want to write your own class that’s derived from ComboBoxListener()

class MyClass : public ComboBoxListener
       /* whatever variables you need and
           whatever pure virtual methods need to be overloaded */

than write the code for the class to do the hard work and pass your class as a ComboBoxListener

MyClass *test = new MyClass();

and now your code is the listener. Neat ha ?

Thank you. It think I get it.