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 7438805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:36:39+00:00 2026-05-29T10:36:39+00:00

I’d like to apply __declspec(nothrow) on some of my member functions that return object

  • 0

I’d like to apply __declspec(nothrow) on some of my member functions that return object references. For example, I’d like to add it to this function (in MyClass.h):

CMyClass& operator= ( IN UInt32 nValue )
{
    return ( SetValue ( nValue ) );
};

The VC++ documentation says that I need to add it after the return type of the function like so:

return-type __declspec(nothrow) [call-convention] function-name ([argument-list])

If I follow this, most of my functions work fine with __declspec(nothrow). However, when I do that for the above member function (or any others that return a CMyClass&), I get compile errors:

error C2059: syntax error : '__declspec(nothrow)'

I can put it in front of the return type and it compiles then but the documentation also says that if a __declspec() is placed in the wrong place, the compiler may ignore it without warning or error.

What’s the right way of using __declspec(nothrow)?

  • 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-29T10:36:40+00:00Added an answer on May 29, 2026 at 10:36 am

    I believe (but am not 100% certain) the correct syntax is:

    CMyClass __declspec(nothrow) & operator= ( IN UInt32 nValue )
    

    It seems that the compiler follows the same rule for function declarations as it does for simple declarations, and the & (or *) goes after the declspec. This matches some of the MSDN documentation.

    The __declspec keywords should be placed at the beginning of a simple declaration. The compiler ignores, without warning, any __declspec keywords placed after * or & and in front of the variable identifier in a declaration.

    As others have pointed out, though, this is something of a waste of time. throw() doesn’t have the same odd parsing issues, and the documentation specifically states that it is equivalent.

    Given the following preprocessor directive, the three function declarations below are equivalent:

    #define WINAPI __declspec(nothrow) __stdcall

    void WINAPI f1();
    void __declspec(nothrow) __stdcall f2();
    void __stdcall f3() throw();

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I've got a string that has curly quotes in it. I'd like to replace
i got an object with contents of html markup in it, for example: string
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.