Thread: What is :: for?

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

    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?
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    428
    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 ::?".
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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,815
    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%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  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