Q:

Passing objects in C++ gives 'invalid use of non-static member' error

So, I'm making a game in which when the thrower(a ball) lands on the trampoline, I need to make the thrower's speed change.
I already have a function called detect_collision in main which is in the file main.cpp
So, in the trampoline class, I have this function:
trampoline.cpp:
#include "trampoline.h"
#include "main.h"
#include "thrower.h"

//other functions

void Trampoline::landed(Thrower* thrower){
    if (detect_collision(this->bounding_box, thrower->bounding_box))
        thrower->speed.y = -2* thrower->speed.y;
  }

In main.cpp:
#include "trampoline.h"
#include "main.h"
#include "thrower.h"

// other functions    

bool detect_collision(bounding_box_t a, bounding_box_t b) {
        return (abs(a.x - b.x) * 2 < (a.width + b.width)) &&
               (abs(a.y - b.y) * 2 < (a.height + b.height));
    }

When I compile, I get the following error:
error: invalid use of non-static member function ‘bounding_box_t Trampoline::bounding_box()’
     if (detect_collision(this->bounding_box, thrower->bounding_box))
                                                                   ^

Other similar questions haven't helped much.

A:

Seems like you have defined thrower->bounding_box as a member function not a member variable. So you need to use it as thrower->bounding_box()
So your code should be
#include "trampoline.h"
#include "main.h"
#include "thrower.h"

//other functions

void Trampoline::landed(Thrower* thrower){
    if (detect_collision(this->bounding_box, thrower->bounding_box()))
        thrower->speed.y = -2* thrower->speed.y;
  }

