c++pointerssdl-2scope-resolution

Applying scope resolution operator causes compiler to choke


I'm using SDL's RenderCopy function:

SDL_RenderCopy(Game::mRenderer, Game::mTexture, &mSourceRect, &mDestinationRect);

The final two arguments are the source and destination rect to copy an image to and from, it is expecting a pointer to the rects, the code above works as one would expect, and they are typed as "SDL_Rect Game::mSourceRect", again, as you would expect for a member variable.

I get an issue whenever I try to apply a scope resolution operator to the rects when they are passed to this function and this function only:

SDL_RenderCopy(Game::mRenderer, Game::mTexture, &Game::mSourceRect, &Game::mDestinationRect);

The error is:

argument of type "SDL_Rect Game::*" is incompatible with parameter of type
 "const SDL_Rect *" SDL2Refresher

If you check the type that &Game::mSourceRect is, it resolves to be the exact same thing as if I don't use the scope resolution operator, my question then is why on earth would this cause the code to not compile?

In the error list, it says "SDL_Rect Game::* is not compatible with parameter of type "const SDL_Rect *" " if that helps at all.

I can just not use a scope resolution operator on these two arguments, but I habitually just use it because I write C# all day at work and I'm constantly explicitly accessing things by their namespace and so it's hard for me to not scope things when I do it so often (plus explicitly scoping something like this isn't a bad thing to begin with so I'd like to just stick with it).


Solution

  • Could you check if &(Game::mSourceRect) as an argument works? The compiler error looks like it is treating the class and scope as part of the type. Maybe if you evaluate the type first (with the brackets) then apply the address of (&) outside the brackets.