Hello and help!

Hello everyone.

My enquiry is a little bit of an abstract one, compared to a specific programming question.

I've recently started learning C++, and rather than learning it to be a programmer per se, I'm learning in a guerrilla fashion for a single purpose. I'm not very good at learning in the typical manner; I work better by getting a grasp of a concept in general, then starting off with the first step in achieving what I want and filling in the blanks. I have ploughed through tutorials and feel that I have a good handle on the basics, such as functions, pointers & referencing and the concept and basic syntax of OOP. I completely understand that programming a full project rather than working my way up from basic tasks may seem counter-intuitive by some, and perhaps foolish by others. It is however, how I seem to cope best, and not lose interest or motivation.

My issue is, of course, that C++ is huge and often un-specific. My previous experience is of a visual programming language (Max/MSP - boxes and cables style), which has given me a lot of useful knowledge and working methods, but C++ is a different beast.

I am using a library called JUCE which is very good for doing what I want to do, and presents an environment and toolbox that will cut out a large part of the bulk, and often unrelated, work. I am also using Xcode.

My question is, are there any guides, or places of advice that can offer a more 'top down' method of approach to C++? An example of a difficult step that I am overcoming is that it seems easy (from the JUCE guide) to initialise a main application screen and implement mouse listening and textual feedback. Yet I am at a loss as to how to say, send the mouse down report to another place to, say, run a function, alter an array, or initialise a gui object on screen. I am aware that pointers would be involved, but there's a blank space between the basics and structure that I'm not getting. I understand the code and the syntax, but 'putting it all together' is eluding me.

Any help would be greatly appreciated, thank you.
Quick look on the JUCE API tells that each Component (like the main screen) is a MouseListener and thus has member function
virtual void mouseDown (const MouseEvent &event)

When you press mouse over Component's area, this function will be called and the 'event' parameter has details, like the mouse position and which buttons were pressed.

You can create a new class that inherits from the window that you were using and reimplement mouseDown. Have you gone through the concepts of class inheritance, polymorphism, and virtual functions?

However, JUCE has an alternative. Keep using a Component from JUCE but create a class that inherits from MouseListener and reimplements the mouseDown. Then create a listener object and "register" it for your Component. The thing is that even though a Component is a MouseListener, it can have a list of MouseListeners too and the mouseDown of each will be called when you press a button.

What is the difference? A member function of a window can access the members of that window, while a separate listener is an outsider.


The other concept used here is callback. You provide a function and the system calls it at some situation. Many C++ standard library algorithms make use of that idiom.
Thank you keskiverto. I have indeed gone through those concepts, although I imagine that knowing and implementing will be a different ball game.

You've given me some very good avenues for investigation on the mouse front. I find the API a little confusing but I'm beginning to understand it more. My understanding was that when you had an encompassing library of functioning units, the task was to then 'patch' them into the 'engine' of the program. From what I gather from your response, the answer is to create inherited classes that route the data as I see fit, correct? (apologies for my lack of nomenclature knowledge).
Topic archived. No new replies allowed.