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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:17:24+00:00 2026-05-28T13:17:24+00:00

I am currently trying to get into writing proper C++ code (getting it running

  • 0

I am currently trying to get into writing proper C++ code (getting it running was ok for some small prototypes, but it’s been ugly).

I recently realized the difference of heap and stack instantiation (O m = new O() vs. O m()).

Now I have a class, where the header file defines a variable, which holds an table definition.

ChunkLoader.hpp:

TablePartion *tablePartial_;

ChunkLoader.cpp:

ChunkLoader() { tablePartial_ = new TablePartial(true, 0, 1); }

Now I want to instantiate the tablePartial on the stack, but I cannot use:
TablePartial tablePartial_(true, 0, 1);

I am totally blind? How can I allocate tablePartial_ on the stack?
Or I am getting it totally wrong, and I cannot use in the constructor since it would be out of scope after the constructor and thus be freed? But since I read that stack variables are better performance-wise, I’d like to use stack instantiation (and getting red of delete).

Main reason: stack overflow told me to get rid of pointers when ever possible. 🙂

  • 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-28T13:17:25+00:00Added an answer on May 28, 2026 at 1:17 pm

    To start off, you should probably avoid the terms “on the stack” or “on the heap”, they’re implementation details that have nothing to do with the concepts being discussed. Instead, we discuss the lifetime of the object, in terms of automatic (which more or less correlates with the stack), dynamic (which more or less correlates with the heap), static (which more or less correlates with globals), and thread (which is a thread-specific global).

    In answer to your specific question, you can use constructor initializers to initialize your variable:

    ChunkLoader() 
       : tablePartial_(true, 0, 1) 
    { 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get into Java web development but seem to be running into
I'm currently trying to get into the Java EE development with the Spring framework.
I'm currently trying to get the output of an executable console-app into an other
I have been trying to get more in to TDD. Currently keeping it simple
I have been running into some troubles recently and I think I need your
Currently, I'm trying to learn Javascript by writing my code in Gedit then attempting
Currently i am trying to get into jQuery and jQtouch for the development of
I'm currently trying to get users to submit data via PHP/HTML forms and into
I'm new to C but trying some system calls. I'm writing program that iterates
Currently, I'm trying to get a list of advertisers (See http://code.google.com/apis/gan/v1beta1/advertisers/list.html ) with my

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.