0

This is a beginner question. I'm pretty sure many people had this doubt but I still didn't find something to clearfy my mind, maybe I'm looking in the wrong direction or conception. The thing is, I can work with both codes:

    sf::Clock clock;
    clock.getElapsedTime();

    sf::Clock getElapsedTime();

Both are accepted through the IDE but I can't really understand the difference. As I already programm other languages I do know that clock.getElapsedTime(); will return the time during the app open, but what does sf::Clock getElapsedTime(); do exactly?

thanks in advance

Victor Oliveira
  • 3,293
  • 7
  • 47
  • 77
  • 4
    This calls for a [book](http://stackoverflow.com/q/388242/1168156) – LihO Aug 28 '13 at 14:05
  • 3
    You're mixing idioms here. If you do OO, objects have "methods" and "attributes". In C++, classes have "members" that are either "member functions" or "member data". – Pete Becker Aug 28 '13 at 14:06

3 Answers3

5

First calls a member function getElapsedTime through object named clock while,
the second just declares a non-member (free) function by name getElapsedTime which returns a object of type sf::Clock and takes no arguments.

Good Read:
What is a function declaration?

MSalters
  • 173,980
  • 10
  • 155
  • 350
Alok Save
  • 202,538
  • 53
  • 430
  • 533
2

"what does sf::Clock getElapsedTime(); do exactly?"

It declares the function named getElapsedTime that takes no arguments and returns the value (an object) of type sf::Clock.

LihO
  • 41,190
  • 11
  • 99
  • 167
1
     sf::Clock getElapsedTime(); 

declares a function getElapsedTime() which returns a sf::Clock object. You need (or somebody else) to define this function somewhere else though.

CS Pei
  • 10,869
  • 1
  • 27
  • 46