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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:14:15+00:00 2026-05-15T13:14:15+00:00

In brief, my question is about member variables as pointers in unmanaged C++. In

  • 0

In brief, my question is about member variables as pointers in unmanaged C++.

In java or c#, we have “advanced pointer”. In fact, we can’t aware the “pointer” in them. We usually initialize the member of a class like this:

member = new Member();

or

member = null;

But in c++, it becomes more confusing. I have seen many styles: using new, or leave the member variable in stack.

In my point of view, using boost::shared_ptr seems friendly, but in boost itself source code there are news everywhere. It’s the matter of efficiency,isn’t it?

Is there a guildline like “try your best to avoid new” or something?

EDIT

I realize it’s not proper to say “leave them in stack”, here’s a more proper way to say: when i need an object to be my member variable, should i prefer a object than a object*?

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

    The Boost source code is not a good example for how you should write your source code. The Boost libraries are designed to wrap up all the tedious, difficult, and error-prone code so that you don’t have to worry about it in your code.

    Your best bet is to follow two general rules in your code:

    • Don’t use pointers where you don’t need to use pointers
    • Where you do need to use pointers, use smart pointers (like shared_ptr or scoped_ptr)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Brief question What command can I use to make my DataSet refresh it's connection
Brief Idea about the flow : I have say minimum 1 and maximum 18
Brief intro about my requirement. I have an empty JSF dataTable. Now, when I
My question is concerned about group of settings that can be found within development
I have a brief question regarding the plot3 function in MatLab. Say I write
I just have a brief question regarding MatLab. Say that we have the equation:
Question about threading to satisfy my curiosity... Let's say I have static variable _status
I have a question about the use of the strongly typed model in Razor
I have rather simple, I imagine, question about CRTP , but I cannot seem
I have asked a question about Incr Pool Size or Decr Pool Size How

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.