Thread: double semicolon in front of a function call??

  1. #1
    Registered User
    Join Date
    Jul 2008

    double semicolon in front of a function call??


    I was reading "Inside COM" book published by Microsoft Press, and one of the examples
    in the book of client implementation had following codes.

    #include <Iface.h>
    #include <objbase.h>
    HRESULT hr = ::CoCreateInstance(...arguments...);

    In this code, why was double semicolon "::" placed in front of CoCreateInstance(...)?
    I saw this in numerous occasions, but I could not find a good document stating
    this issue. I would very much appreciate for your help.

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    Firstly, it's not semicolon, it's just colon (I think that's what it's called anyway). ; is semicolon.
    Anyway, it merely tells the compiler to look for the function inside the global namespace. I doubt it's necessary here; it's more of a programming style.
    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.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Oh yeah, I used wrong words there. Thank you for clarifying it for me. Now it's all clear.

  4. #4
    The larch
    Join Date
    May 2006
    I guess it might be useful to clear up ambiguous situations such as the following:

    #include <iostream>
    namespace my_names
        void foo() { std::cout << "my_names::foo()\n"; }
    void foo() { std::cout << "foo()\n"; }
    int main()
        using namespace my_names;
        //foo();  //error, which foo() to use?
        ::foo();  //foo()
        my_names::foo(); //my_names::foo()
    In the book it is probably more like a style issue as Elysia says.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Conversion From C++ To C
    By dicon in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 02:54 PM
  3. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM