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 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

I asked a question here about an Linq error that results from mixing Linq-To-SQL
Let's put Heisenberg aside for a brief moment. How would I go about to,
I'm new to PHP, so this question might best be answered by a brief
I have a website registration page, and I'm trying to compile a list of
I've just found out about Stack Overflow and I'm just checking if there are
I've done a brief Google around and found nothing but I feel I ought
related to this question my script basically runs fine but sometimes it stop responding
Pylint is doing something odd on my Windows box - something that shouldn't be
So after reading Performance in PDO / PHP / MySQL: transaction versus direct execution

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.