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

  • Home
  • SEARCH
  • 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

SO I found this sweet code to use Gmail in as the SMTP server
I have found this example on StackOverflow: var people = new List<Person> { new
I found a jquery snippet of code for counting down the characters when you
Goal: Best system for refactoring complex & ugly code in exactly the same file.
I've found several jQuery syntaxes for nullifying the enter on a form. First one:
I'm using the 'TPCircularBuffer' class for creating a circular buffer object, from this website
I found the mvc 3 rtm project on codeplex. What does RTM stand for?
I know similar question was answered a lot times before, but I hope this
WebKit has a lot of pre-processor lines like this: #if MACRO1(MACRO2) For example: #if
I am playing with TFS 2010, and am trying to setup a build process

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.