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 asked this question: Expose XML or Objects - thanks all for the
I used an application recently that was awe-inspiring. All the forms inherited from their
I run my blog using Wordpress and all too recently became a big believer
We recently were given a client requirement to encrypt all their data while at
I just recently changed out all my hard drives and in the process of
Recently there has been quite some hype around all the different mocking frameworks in
I have recently started exploring Maven, but I feel a bit overwhelmed of all
I have recently learned the Ruby programming language, and all in all it is
I was involved in couple of cloud computing platform recently. First of all please
If all tables I want to delete from have the column gamer_id can i

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.