Question

I'm really confused at the moment. It's been a while since I touched C++ and I want to get back into it again, so I'm trying to use SFML, and I'm using a guide along side it. The thing that gets me is this code.

Game::Game():mWindow(sf::VideoMode(640, 480), "SFML Application") {
}

It works perfectly, and I think I understand. It's initializing mWindow, and when mWindow is constructed, it creates the window. No problem. But when I put this code down.

Game::Game() {
    mWindow(sf::VideoMode(640, 480), "SFML Application");
}

It gives me the error Type 'sf::RenderWindow' does not provide a call operatorwhich I have no idea what that means, nor do I understand how those two blocks of code differ.

Was it helpful?

Solution

mWindow should be a class data member, not a function.

First block of code simply initializes it.

OTHER TIPS

The error it's giving you is because in your second example, this:

mWindow(sf::VideoMode(640, 480), "SFML Application");

Should be this:

mWindow = sf::VideoMode(640, 480), "SFML Application";

It's not going to work anyway, as sf:RenderWindow inherits from sf::NonCopyable.

The error is actually quite descriptive, 'sf::RenderWindow' does not provide a call operator. mWindow is of type sf::RenderWindow. You're trying to call it like a function, mWindow(), which it is not.

You should use the initializer list in your first example. This will ensure the the mWindow member is constructed once.

This is called Constructor Initialization Lists and it actually should be something like this in your second example:

Game::Game() {
    this.mWindow = new sf::RenderWindow(sf::VideoMode(640, 480), "SFML Application");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top