What are your pointers pointing at?
You never assign them.
You go like this:
MyPointer = MyFunction(MyPointer);
MyFunction(MyPointer)
{
return MyPointer;
}
You are setting an uninitialized pointer to point to the result of a function... but you are passing in your pointer (uninitialized) to that function and then returning that uninitialized pointer to initialize itself. My sentence doesn't really make sense... because I'm trying to describe your code which also doesn't make sense.
If you cut out your function, which never actually creates any variable to point to anyway, you basically get this:
SDL_Rect *Rect = Rect;
...which does nothing worthwhile or meaningful.
Have you learned how pointers work? Just like my dog, they can bite you if you don't know how to handle them properly - but also just like my dog, they aren't anything to fear either, you just have to learn how to handle them - which is easy, once you learn it. Rather then go into a pointer tutorial here, many programmers have already written loads of pointer tutorials just a google away, and can explain it better than I can. I strongly encourage you to go review some of those; meanwhile I'll just help you rewrite your function.
Here are four different functions that do what you want - they all work fine. If you have any questions about how they work, just ask!
Return-by-value version:
SDL_Rect Init(int XPos, int YPos, int Width, int Height)
{
SDL_Rect Rect;
Rect.h = Height;
Rect.w = Width;
Rect.x = XPos;
Rect.y = YPos;
return Rect;
}
//Use like this:
SDL_Rect myRect = Init(5, 5, 50, 20);
Pass-by-reference version:
void Init(SDL_Rect &Rect, int XPos, int YPos, int Width, int Height)
{
Rect.h = Height;
Rect.w = Width;
Rect.x = XPos;
Rect.y = YPos;
}
//Use like this:
SDL_Rect myRect;
Init(myRect, 5, 5, 50, 20);
Pass-by-pointer version:
void Init(SDL_Rect *Rect, int XPos, int YPos, int Width, int Height)
{
Rect->h = Height;
Rect->w = Width;
Rect->x = XPos;
Rect->y = YPos;
}
//Use like this:
SDL_Rect myRect;
Init(&myRect, 5, 5, 50, 20);
Dynamic memory / return-by-pointer version:
SDL_Rect *Init(int XPos, int YPos, int Width, int Height)
{
SDL_Rect *Rect = new SDL_Rect;
Rect->h = Height;
Rect->w = Width;
Rect->x = XPos;
Rect->y = YPos;
return Rect;
}
//Use like this:
SDL_Rect *myRect = Init(&myRect, 5, 5, 50, 20);
//And don't forget to free it when done (or you'll have a memory leak).
delete myRect;