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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:32:44+00:00 2026-05-29T23:32:44+00:00

There is two different scenarios I’m after: You have a shared_ptr You have a

  • 0

There is two different scenarios I’m after:

  1. You have a shared_ptr
  2. You have a unique_ptr

The answer might be the same though.

Consider a method, which uses a pointer but does not assume ownership:

void use_pointer(T ptr)
{
    ptr->act();
}

Should T be

  • my_type * (raw pointer)
  • const shared_ptr<my_type> & (sending const ref, if using shared_ptr)
  • const unique_ptr<my_type> & (sending const ref, if using unique_ptr)
  • weak_ptr<my_type> (constructing weak_ptr for method call)

Something else? Thanks!

  • 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-29T23:32:45+00:00Added an answer on May 29, 2026 at 11:32 pm

    If you do not assume ownership, then preferably accept a reference to the pointee. If you want to express optionality, you can use a raw pointer, or you can use e.g. boost::optional<U&> (where U is the pointee type).

    Functions that do no assume ownership should almost never accept a smart pointer. There is in general nothing useful for the callee in a smart pointer interface other than means of getting to the pointee. So pass that instead.

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

Sidebar

Related Questions

Lets say there are two pages with two different html elements which have the
There are two different ways to create an empty object in JavaScript: var objectA
There are two pictureboxes with two different images. If I click on one picture
In our setup there are two different websites in IIS 7 setup that point
In struts I notice there are two different ways to access variables. I am
As I see it there are two different types of logging: User-focused logs, like
Is there anyway to batch two different select queries to either SQLite or SQLCE
There is a page on our server that's reachable via two different URLs. http://www.spotlight.com/6213-5613-0721
I was just wondering if there is any difference between the two different new
How can I easily use two different databases for debug and release scenarios? 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.