I am building a pong game in SDL2 as my first assignment for my game development class. I've encountered an error involving SDL_Rect that I can't figure out. I am using SDL_Rects in conjunction with SDL_HasIntersection(const SDL_Rect * A,const SDL_Rect * B) to detect collisions, and I have the collide method in the actor superclass from which all actors (pong ball, paddles, etc) inherit. Here is my code for actor.cpp:

#include "actor.h"


 Each actor has
-position (2D vector)
-speed and direction (2D vector)
-bounding box (SDL_Rect)
-strings to define file path for texture (needed when drawing window)

Each child of actor must implement
-setBoundingBox (will be different for each actor)

Each actor can implement
-collide(const &actor)


    imageFilePath = "";

    SDL_Rect rect;

    boundingBox = rect;

    vec2D placeholder(0.0f, 0.0f);

    directionVelocity = placeholder;

    position = placeholder;


SDL_Rect actor::setBoundingBox() //must be overwritten, sets bounding box
    SDL_Rect placeholder;
    placeholder.w = 0;
    placeholder.w = 0;
    return placeholder;

bool actor::collide(const &actor) const //checks if an actor is colliding with another 
    if (SDL_HasIntersection(&boundingBox, &actor.boundingBox))
        return true;
    return false;

vec2D actor::getPosition() //gets actor's current position
    return position;

vec2D actor::getDirectionVelocity() //gets the actor's current direction and velocity
    return directionVelocity;

void actor::updatePosition(vec2D newPos) //updates both the actor's bounding box and 
position using a new position vector (intended for ball and paddles)
    boundingBox.x = newPos.u;
    boundingBox.y = newPos.v;
    position = newPos;

The error I am getting is:

error: request for member 'boundingBox' in 'actor', which is of non-class type 'const 
46 |     if (SDL_HasIntersection(&boundingBox, &actor.boundingBox))

I'm not sure how to get around this. Could it be because the actor's boundingBox member in the constructor is set to an incomplete SDL_Rect? That SDL_Rect rect is just a placeholder, and I have a virtual setBoundingBox() function in my actor.h file that each subclass must override. The actor class itself is never instantiated in my main function, just subclasses of it.

  • 2
    \$\begingroup\$ It sounds like somehow actor::collide is getting called with an argument that's an integer instead of an actor. Is it possible in your collision-testing loop you've accidentally passed the index of the item instead of the item at that index in the collection? \$\endgroup\$
    – DMGregory
    Feb 11 at 20:55
  • \$\begingroup\$ The collide function's argument list looks a bit weird to me, or maybe I'm missing something. Is the &actor argument the data type or the actor passed in? Shouldn't it be bool actor::collide(const actor& theOtherActor)? \$\endgroup\$ Feb 17 at 20:42


You must log in to answer this question.

Browse other questions tagged .