Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: creating functions like getGlobalBounds()  (Read 1826 times)

0 Members and 1 Guest are viewing this topic.

HammaJamma

  • Newbie
  • *
  • Posts: 12
    • View Profile
creating functions like getGlobalBounds()
« on: June 17, 2014, 02:50:10 am »
I want to create a function that can return multiple values based on the given criteria like getGlobalBounds().
getGlobalBounds can return top, left, height and width depending how you call the function. i.e. getGlobalBounds().height

what is this type of function called and can anyone link me to any documentation on how to create something similar?

ElysianShadow

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: creating functions like getGlobalBounds()
« Reply #1 on: June 17, 2014, 04:34:46 am »
You should look into Structures and Classes, and how to return them from a function.

For example:


class MyClass
{
     public:
     
     MyClass() {}
     
     struct Position
     {
          float x;
          float y;
     };

     Position getPosition() { return m_position; }

     private:

     Position m_position;
};

 

In the above code, when you call getPosition() you are returning the member variable "m_position" which itself has two member variables "x" and "y". These can be called using the "." operator right from the function. So for example if you wanted to access the "x" variable inside m_position, you could do:


MyClass obj;

float x = obj.getPosition().x;

 

But again, you should really read up on structures and classes. It's something basic you should know before you try using SFML

HammaJamma

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: creating functions like getGlobalBounds()
« Reply #2 on: June 17, 2014, 04:56:16 am »
In the above code, when you call getPosition() you are returning the member variable "m_position" which itself has two member variables "x" and "y". These can be called using the "." operator right from the function. So for example if you wanted to access the "x" variable inside m_position, you could do:
THANK YOU!! I figured it was something simple like this but it's hard to learn certain things when you don't even know what to search for.

Quote
But again, you should really read up on structures and classes. It's something basic you should know before you try using SFML
I do realize that this question was a c++ question and not a question about SFML but I'm using SFML to make learning c++ a little more fun, anyways, I do appreciate the answer.