SFML community forums

Bindings - other languages => C => Topic started by: c-jay on April 26, 2016, 03:24:47 pm

Title: sfFloatRect_set function
Post by: c-jay on April 26, 2016, 03:24:47 pm
Hi this works fine:

#include <SFML/Graphics.h>

sfVector2f sfVector2f_set(float x, float y){
        sfVector2f vector2f;

        vector2f.x = x;
        vector2f.y = y;

        return vector2f;
}

int main(){
sfVector2f vector;
vector.x = sfVector2f_set(1, 1).x;
}
 
But this throws error: request for member top in something not a structure or union
#include <SFML/Graphics.h>
sfFloatRect sfFloatRect_set(float top, float left, float width, float height){
        sfFloatRect floatRect;

        floatRect.top = top;
        floatRect.left = left;
        floatRect.width = width;
        floatRect.height = height;

        return floatRect;
}

int main(){
sfFloatRect floatRect;

// throws error: request for member top in something not a structure or union      
floatRect.top = sfFloatRect_set(1,1,1,1).top;              
                                                       
}
 

I think it could be a basic c problem but i'm very thankful for a reason.
Title: Re: sfFloatRect_set function
Post by: Laurent on April 26, 2016, 03:30:32 pm
"doesn't work" is a very bad description of your problem. Please give the exact compiler error, as well as the corresponding line in source code.
Title: Re: sfFloatRect_set function
Post by: c-jay on April 26, 2016, 03:44:02 pm
I'm very sorry, I edited my post with an description
Title: Re: sfFloatRect_set function
Post by: Hiura on April 26, 2016, 06:05:23 pm
With the exception of main's return type being int (google why), this works just fine (http://ideone.com/uvEzmo).
Title: Re: sfFloatRect_set function
Post by: c-jay on April 26, 2016, 06:54:29 pm
With the exception of main's return type being int (google why).
i fixed it in the main post but my code still throw the same error
Title: Re: sfFloatRect_set function
Post by: eXpl0it3r on April 26, 2016, 07:10:05 pm
And the error would be...? ::)
Title: Re: sfFloatRect_set function
Post by: c-jay on April 26, 2016, 07:36:39 pm
And the error would be...? ::)

// throws error: request for member top in something not a structure or union      
floatRect.top = sfFloatRect_set(1,1,1,1).top;      
 
         
Title: Re: sfFloatRect_set function
Post by: Laurent on April 26, 2016, 08:18:16 pm
Is it the actual code that gives you the error, or is it a simplified version for the forum, that you never compiled?
Title: Re: sfFloatRect_set function
Post by: c-jay on April 28, 2016, 05:45:45 pm
Is it the actual code that gives you the error, or is it a simplified version for the forum, that you never compiled?

Thank you very much! I forgot to declare the prototype...  :-[