What is :: for?

This is a discussion on What is :: for? within the C++ Programming forums, part of the General Programming Boards category; Hey, Slow in here today I guess I'll throw something out here. Apparently google ignores :: in a search or ...

  1. #1
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407

    What is :: for?

    Hey,

    Slow in here today I guess I'll throw something out here. Apparently google ignores :: in a search or it doesn't turn up many useful results.

    I started playing around with a new library and it has you declare variables alot using :: such as

    Code:
    sf::window App(sf::VideoMode(800, 600, 32), "Window Title");
    When I define classes I use that operator, but I never used one to declare before, nor have I ever written code that I was required to do so. So I had to wonder what am I doing? Or in another way why am I using the :: here?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,598
    That is the scope resolution operator. My guess is that sf is a namespace name, hence sf::window is a name, e.g., a type name, in that namespace.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    That is the scope resolution operator
    Thats exactly what I needed. Thanks!

    Alot more useful things show up when googling "scope resolution operator" vs googling "what is ::?".

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,299
    Even better, read about all the operators here:
    Operators in C and C++ - Wikipedia, the free encyclopedia
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Quote Originally Posted by Lesshardtofind View Post
    When I define classes I use that operator, but I never used one to declare before, nor have I ever written code that I was required to do so. So I had to wonder what am I doing? Or in another way why am I using the :: here?
    Yes, you have?
    You know, everything in STL lies in the std namespace, so

    vector<int> v;

    won't work, but

    std::vector<int> v;

    and

    using namespace std;
    vector<int> v;

    will both work.
    Just substitute std and vector for something else and you have a namespace, such as sf and window.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,253
    All classes/structs in C++ are alsoi associated with a scope with the same name as the class/struct.

    So, given something like
    Code:
    sf::window App(sf::VideoMode(800, 600, 32), "Window Title");
    sf may be either a namespace or a class/struct type.
    Right 98% of the time, and don't care about the other 3%.

  7. #7
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by grumpy View Post
    sf may be either a namespace or a class/struct type.
    While that is true, in this particular case, it is a namespace, not a class:

    SFML - Simple and Fast Multimedia Library
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21