Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6199673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:13:51+00:00 2026-05-24T04:13:51+00:00

I found this source code: inline GUID& WString2Guid(wstring src) { static GUID result; HRESULT

  • 0

I found this source code:

inline GUID& WString2Guid(wstring src)
{
    static GUID result;
    HRESULT hr = ::CLSIDFromString(W2OLE(const_cast<WCHAR*>(src.c_str())), &result);
    if (FAILED(hr)) {
        //ERROR: The string '%s' is not formatted as a GUID!
        throw(E_INVALIDARG);
    }
    return result;
}

What’s the use of returning a reference here? The calling code cannot get a reference anyway because the variable would have left its scope by then. So does this little & sign make any difference?

To clarify/extend the question: In the same example program, the function is called as

GUID guid = WString2Guid(id); // way 1

If I wanted to make use of the reference, wouldn’t I have to call

GUID& guid = WString2Guid(id); // way 2

instead?

And another question; why is the CLSIDFromString function called with the :: scope operator before? This would only make any sense if there was another local function declared with the same name, wouldn’t it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:13:52+00:00Added an answer on May 24, 2026 at 4:13 am

    No. result is a static local variable, so it will exist even after the function exit. Don’t confuse this with non-static local variable.

    :: in ::CLSIDFromString tells the compiler to choose CLSIDFromString from the global namespace, in case if there are many definition of CLSIDFromString defined in other namespace(s), visible at the call-site.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking at SharpDevelop source code I found this button declaration: <Button Style={x:Static core:GlobalStyles.ButtonStyle} Content={core:Localize
I am a beginner in C. While reading git's source code, I found this
I found this example PHP source code at HTTP POST from PHP, without cURL
I am reading some source code and I found this statement at the very
Browsing through the source code of Microsoft's sample StockTrader application, I found this snippet
I found this while reading some source code. #define MACRO(x) if((void) 0, (x)); else
Looking at some source code, I found this operator () => { } From
I found this sample source code for C# from How to convert a Unix
I have found this in a JavaScript source code file: function getElementsByClass(_0x62cbx2, _0x62cbx3, _0x62cbx4)
I found this example when I ran PCLint on the source code of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.