double semicolon in front of a function call??

This is a discussion on double semicolon in front of a function call?? within the C++ Programming forums, part of the General Programming Boards category; Hi, I was reading "Inside COM" book published by Microsoft Press, and one of the examples in the book of ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    19

    double semicolon in front of a function call??

    Hi,

    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
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    19
    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
    Posts
    3,573
    I guess it might be useful to clear up ambiguous situations such as the following:

    Code:
    #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, 05:54 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    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

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