Odd functions

So i'm studying this SFML book, And this is a section that confuses me quite a bit, i know what it does, and what every thing means, its specifically the syntax in which its used.

1
2
3
4
5
6
7
8
 Game::Game()
: mWindow(sf::VideoMode(640, 480), "SFML Application")
, mPlayer()
{
mPlayer.setRadius(40.f);
mPlayer.setPosition(100.f, 100.f);
mPlayer.setFillColor(sf::Color::Cyan);
}

I do understand that this is declaring the function of the default constructor in class "Game". What i do not understand is the use of : to then use an earlier defined function. I've never seen that before. The only use of a single : i know of is to inherit from other classes. (or to declare functions) like
1
2
3
4
5
6
class Example2 {
  public:
    int total;
    Example2 (int initial_value) : total(initial_value) { }; // <--- that
    void accumulate (int x) { total += x; };
};
OR
1
2
class thing : public thingy{ // <---- that
}


But back to the original question , i dont understand, using one : in the default constructor?
1
2
3
4
5
6
7
8
 Game::Game()
: mWindow(sf::VideoMode(640, 480), "SFML Application")
, mPlayer()
{
mPlayer.setRadius(40.f);
mPlayer.setPosition(100.f, 100.f);
mPlayer.setFillColor(sf::Color::Cyan);
}

also this is the class declaration (for reference to variables)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Game
{
public:Game();
void run();
private:
void processEvents();
void update();
void render();
private:
sf::RenderWindow mWindow;
sf::CircleShape mPlayer;
};
int main()
{
Game game;
game.run();
}

EDIT:now that i look at my post. I just realized, that i semi answered my own question. it is declaring a function but when i posted what i knew with the empty brackets, what there doing is actually putting something in those brackets.I mostly learned c++ from this site, these tutorials don't show use of that. Which is probably why i got confused.
Last edited on
Well, it actually isn't using it for inheritance. That is actually an initializer list- basically, using an initializer list lets you do things such as declare constants in constructors, or call parent constructors.
Topic archived. No new replies allowed.