Thread: Conflicting pointer with type - not sure.

  1. #1
    Registered User
    Join Date
    Dec 2016
    Posts
    20

    Conflicting pointer with type - not sure.

    Could someone please help me sort out the conflicting types I'm suffering.


    Code:
    I have this function:
    
    SDL_Rect sprite_getClipRect(Sprite *ptr_sprite, int col, int row)
    {
        return ptr_sprite->clip[col][row];
    }
    
    And I'm trying to use it here:
    
    SDL_RenderCopy(renderer, sprite_getTexture(spaceship_sprite), &sprite_getClipRect(spaceship_sprite, 1, 0), &spaceship_rect);
    
    The cheap fix i used was this:
    
        SDL_Rect rect = sprite_getClipRect(spaceship_sprite, 1, 0);
        SDL_RenderCopy(renderer, sprite_getTexture(spaceship_sprite), &rect, &spaceship_rect);
    
    But I should not need to create this local variable.

    But the return type: SDL_Rect doesn't seem to match the parameter demand of SDL_Rect* source.

    int SDL_RenderCopy(SDL_Renderer* renderer,
    SDL_Texture* texture,
    const SDL_Rect* srcrect,
    const SDL_Rect* dstrect)
    Last edited by Tiago Redaelli; 04-17-2017 at 01:31 PM.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Can you just do this?
    Code:
    SDL_Rect *sprite_getClipRect(Sprite *ptr_sprite, int col, int row) {
        return &ptr_sprite->clip[col][row];
    }

  3. #3
    Registered User
    Join Date
    Dec 2016
    Posts
    20
    no it didn't decided to just create a sprite_renderCopy (which hides that ugly thing).

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    "no it didn't" is very little information to go on. There's no reason why that wouldn't work unless it should return const SDL_Rect*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issues with malloc, returning pointer, conflicting types
    By pointingmachine in forum C Programming
    Replies: 3
    Last Post: 04-04-2013, 08:17 PM
  2. creating a list pointer of parent type from base type...
    By Adamkromm in forum C++ Programming
    Replies: 14
    Last Post: 04-14-2012, 02:07 PM
  3. Replies: 1
    Last Post: 03-24-2008, 10:16 AM
  4. Replies: 17
    Last Post: 03-06-2008, 02:32 PM
  5. Replies: 4
    Last Post: 08-27-2007, 11:51 PM

Tags for this Thread