I have a question, SDLRenderFillRects needs a const SDLRects* parameter but in vector we…
- User
I have a question, SDL_RenderFillRects needs a const SDL_Rects* parameter but in vector we are storing std::vector<SDL_Point> instead of std::vector<SDL_Point*>, why does this work without error?
- Assistant
- User
Sorry I had a typo, the question correctly is this: I have a question, SDL_RenderFillRects needs a const SDL_Rects* parameter but in vector we are storing std::vector<SDL_Rect> instead of std::vector<SDL_Rect*>, why does this work without error?
- Assistant
No problem, let's address the updated question regarding
SDL_RenderFillRectsand the use ofstd::vector<SDL_Rect>.The reason you can use
std::vector<SDL_Rect>without error is becauseSDL_RenderFillRectsexpects a pointer to a contiguous block ofSDL_Rectstructures (i.e., an array ofSDL_Rect), andstd::vectorstores its elements in a contiguous block of memory just like an array. This is why you can pass a pointer to the first element of astd::vectorto functions that are expecting arrays.When you call
SDL_RenderFillRects, you need to provide it with a pointer to the first in your series of rectangles. You can do this using the member function, which returns a pointer to the memory used internally by the vector to store its owned elements. Here's a simple example: