componentMovedOrResized for multiple components

Hi - I have a parent class that listens for when three different child objects are moved / dragged. I know the componentMovedOrResized gives me the &component, but how do I test this to see what one was moved?



Anyone have any advice?

Not sure I understand the question.. It tells you which component it was, so isn't that what you need to know?

Let me see if I can give some details with code. If I try to compare the component to one of my objects that can be moved or resized it gives me an error: "invalid operands to binary expression (Juce::Component and objectName)". For example, something like this:


void Looper::componentMovedOrResized (Component& component, bool wasMoved, bool /*wasResized*/)

    if(component == loopMark1)

    else if(component == loopMark2)
        //other stuff


The question is, since this doesn't work, am I using it wrong or is there some other way I should be testing which object was moved?


if (&component == &loopMark1)




You'll need to read a bit on pointers and inheritance at some point ;-)   But you can't directly compare a base class (Component) with something more complex derived from it (e.g. loopMark) (unless you've got a specially crafted implementation of operator== anyway).

But as Components can't be copied, you can guaranteed that by comparing the addresses you know if you are looking at the right object. 

The reduction of this is: 

class Base
  /* Some stuff. */
class Derived
public Base
  /* Some other stuff. */
void functionOkay()
  Base * b; 
  Derived * d; 
  bool result = b == d; 
void functionErrorAboutBinaryExpression()
  Base b; 
  Derived d; 
  bool result = b == d;  // error here. 

If that helps ..

damn, my pointers & inheritance stupidity, I need to scratch up on c++.


That works, thanks!