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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:47:29+00:00 2026-05-16T21:47:29+00:00

When you create a new object in C++ that lives on the stack, (the

  • 0

When you create a new object in C++ that lives on the stack, (the way I’ve mostly seen it) you do this:

CDPlayer player;

When you create an object on the heap you call new:

CDPlayer* player = new CDPlayer();

But when you do this:

CDPlayer player=CDPlayer();

it creates a stack based object, but whats the difference between that and the top example?

  • 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-16T21:47:30+00:00Added an answer on May 16, 2026 at 9:47 pm

    The difference is important with PODs (basically, all built-in types like int, bool, double etc. plus C-like structs and unions built only from other PODs), for which there is a difference between default initialization and value initialization. For PODs, a simple

    T obj;
    

    will leave obj uninitialized, while T() default-initializes the object. So

    T obj = T();
    

    is a good way to ensure that an object is properly initialized.

    This is especially helpful in template code, where T might either a POD or a non-POD type. When you know that T is not a POD type, T obj; suffices.

    Addendum: You can also write

    T* ptr = new T; // note the missing ()
    

    (and avoid initialization of the allocated object if T is a POD).

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

Sidebar

Related Questions

Hello i'm using map() jquery to create a new object array DEMO but this
I want to create a new object using this $procedure = new ${$s.'\\'.$p}; It
I'm trying to generate a link that creates a new object. It creates the
Is it possible in jax-ws to have a webmethod that creates a new object
When accessing member that doesn't exist, automatically creates the object. $obj = new ClassName();
I am tryıng to create new object of other class ın a for loop.
I'm try to create a new list object. I set the new object to
I'm trying to create a new object of type T via its constructor when
I want code to run whenever I create a new object. For example, see
I am using backbone and trying to create a new object and I am

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.