I'm currently working on a Fruit Ninja clone using SDL and I want to restrict my fruit to being created at a random x co-ordinate, but so that they fully appear within the bounds of the window (800x600). My current code (which is a work in progress) looks something like this:

Which creates a new Fruit at a random x position at the bottom of the window (so it can bounce up into it) and gives it an image.

50 is the width of the Fruit, so to ensure the whole Fruit starts inside the window I take it away from the screen width. I can't access the width through a get() method before the Fruit itself is actually created, so is the best way to do this to make the width a public const static member inside Fruit and use Fruit::width instead of 50 or is there a better way?

Since the fruit object will know it's own size, why not have the fruit constructor call rand()?

Also, since it looks like you're using a C++11 compiler, you can simplify that expression by using std::vector::emplace_back() rather than push_back(). So the call would look something like this instead: