Search code examples
c++csdl

C equivalent of C++'s double colons?


I'm studying C and know nothing about C++. LazyFoo's SDL2 tutorial that uses C++ does a thing with double colons that I don't understand and thus cannot follow in C.

If it helps, here's the link to the tutorial:

http://lazyfoo.net/tutorials/SDL/04_key_presses/index.php

SDL_Surface *loadSurface( std::string path )
{
    //Load image at specified path
    SDL_Surface *loadedSurface = SDL_LoadBMP( path.c_str());
    if( loadedSurface == NULL )
    {
        printf("Unable to load image %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
    }

    return loadedSurface:
}

Everything here makes sense to me except the function parameters and LoadBMP parameters. I don't know what the :: means, and I don't know what path.c_str() is referring to.

Please, could someone explain it in a way that makes sense in C, or suggest a C-only workaround?


Solution

  • In C, loadSurface would be declared as simply

    SDL_Surface *loadSurface(const char *path)
    

    which means the call to SDL_LoadBMP can be written as

    SDL_Surface *loadedSurface = SDL_LoadBMP(path);
    

    The details of what std::string does and why .c_str() is needed are not relevant if you are not interested in learning C++, and in this case are not relevant to the tutorial either.