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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:53:32+00:00 2026-06-11T23:53:32+00:00

I read somewhere (cannot find the source now) that MyClass *p1 = new MyClass;

  • 0

I read somewhere (cannot find the source now) that

MyClass *p1 = new MyClass;

and

MyClass *p2 = new MyClass();

are essentially equivalent, provided that MyClass provides a default constructor. The compiler understands what I want to do and adds the empty parentheses.

If this is the case, why I am not allowed to write

throw MyException;

but have to use

throw MyException();

? (Yep, a question mark at the beginning of a line.)

To add some more confusion, the C++ FAQ suggests that the second usecase (new MyClass()) does not invoke a constructor, but calls function defined with operator() instead.

  • 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-06-11T23:53:33+00:00Added an answer on June 11, 2026 at 11:53 pm

    The compiler understands what I want to do and adds the empty parentheses.

    No it doesn’t; the two expressions aren’t quite equivalent. The difference is in how the objects are are initialised: the first uses default-initialisation, while the second uses value-initialisation. So they are equivalent for classes that define a default constructor; otherwise, the first will leave POD objects uninitialised, while the second will initialise them to zero.

    why I am not allowed to write throw MyException;?

    MyException() is an expression that creates a value-initialised temporary object; you can throw that just like you can throw the value of any other suitable expression.

    MyException isn’t an expression; it’s just a type name. You can only throw the value of an expression, so throw MyException; is not valid. There’s no way to create a default-initialised temporary.

    To add some more confusion, the C++ FAQ suggests that the second usecase (new MyClass()) does not invoke a constructor, but calls function defined with operator() instead.

    No it doesn’t. It says that a declaration like List x(); declares a function with a return type List, not (as one might think) a value-initialised object of type List. It has nothing to do with new-expressions or operator().

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

Sidebar

Related Questions

I read somewhere in Google's reference (and I can not find it again) that
I've read somewhere on MSDN that the equivalent to C#'s is keyword would be
I am new to XML serialization and I have read that private variables cannot
I read somewhere in the docs that WebDriver API's are non blocking (except for
I read somewhere that the ?: operator in C is slightly different in C++,
I read somewhere that Pattern Matching like that supported by the match/case feature in
I read somewhere that somebody could access a config value during run time but
I read somewhere that you would never run syncdb on a database, post its
I read somewhere that body temperature can be measured through touch screen since different
I read somewhere that, overriding is the means by which you get polymorphism. Polymorphism

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.