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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:42:39+00:00 2026-05-12T16:42:39+00:00

All, I recently posted this question on DAL design. From that it would seem

  • 0

All,

I recently posted this question on DAL design. From that it would seem that passing a reference to an object into a function, with the function then populating that object, would be a good interface for a C++ Data Access Layer, e.g.

  bool DAL::loadCar(int id, Car& car) {} 

I’m now wondering if using a reference to a boost::shared_ptr would be better, e.g.

  bool DAL::loadCar(int id, boost::shared_ptr<Car> &car)

Any thoughts? Does one offer advantages over the other?

What would be the implications of applying const correctness to both calls?

Thanks in advance.

  • 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-12T16:42:40+00:00Added an answer on May 12, 2026 at 4:42 pm

    As sbi says, “It depends on what the function does. “

    However, I think the most important aspect of the above is not whether NULL is allowed or not, but whether the function stores a pointer to the object for later use. If the function just fills in some data then I would use reference for the following reasons:

    • the function can still be used by clients who do not use shared_ptr, used for stack objects, etc.
    • using the function with shared_ptr is still trivial – shared_ptr has dereferencing operator that returns a reference
    • passing NULL is not possible
    • less typing
    • I don’t like using “stuff” when I don’t have to

    If the function needs to store pointer for later use or you anticipate the function might change in such a way that will require storing a pointer, then use shared_ptr.

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

Sidebar

Related Questions

I recently posted this question about codes for a gift-card-like voucher that users can
(This question is similar to the one I recently posted here except that now
I was recently reading this discussion at SO where somebody commented that not all
I recently posted this question which worked locally with the answer I selected as
I recently posted a question about a WCF Restful web service that I am
For reference, here is a question on SO that I asked recently that is
I recently posted this question: jqgrid edit form autocomplete="off" by default, how to change
I wanted to list all my Recently Used Items. I use this code: public
I've been looking into setting up a Selenium test suite recently but all of
I recently discovered that all Windows 7 machines have an handwriting recognition API within

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.