Namespace resolution confusion.

I'm a hobbyist programmer self teaching C++. I'm doing ok with the C part but the object oriented part is confusing me. For example I'm currently trying to learn to use the sfml package. I understand that you can declare a VideoMode object like this:

 
 sf::VideoMode vm(1920, 1080);


Clear, simple and understandable. But now to get the current desktop mode the documentations tells me to do this:

 
vm = sf::VideoMode::getDesktopMode();


Why the nested namespace resolution operators? It's like there are nested objects here but why would you do it that way? Making it even more confusing I experimented and found that this also works:

 
vm = vm.getDesktopMode();


The getFullScreenModes() also uses nested namespace resolution operators. But something like vm.getFullscreenMode does not work here.

In general I'm confused about when and why to use the namespace resolution thingy and I am having trouble parsing the documentation.


sf::VideoMode::getDesktopMode() is static member function of VideoMode, you can call it independently of an object.
Ah!!! You call static functions using the namespace thingy. Somehow I blew right past that simple and obvious fact.

But what about the getFullScreenModes() function? How do you call it using an instance of the VideoMode class?

The code from the documentation is:

1
2
3
4
5
6
7
8
std::vector<sf::VideoMode> modes = sf::VideoMode::getFullscreenModes();
for (std::size_t i = 0; i < modes.size(); ++i)
{
    sf::VideoMode mode = modes[i];
    std::cout << "Mode #" << i << ": "
              << mode.width << "x" << mode.height << " - "
              << mode.bitsPerPixel << " bpp" << std::endl;
}


It seems like I need to declare a dynamic array of VideoMode() objects. But I don't know how to do that.

Anyway thanks.




Topic archived. No new replies allowed.