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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:45:01+00:00 2026-06-06T15:45:01+00:00

So when I have code like: shared_ptr<Foo> bar (my_normal_operator<Foo>(mumble)); Even though the type Foo

  • 0

So when I have code like:

shared_ptr<Foo> bar (my_normal_operator<Foo>(mumble));

Even though the type Foo is coming out of left field, it works as the return type is produced solely through an “additive” pattern to what is given:

template <typename Target, typename Source>
shared_ptr<Target> my_normal_operator(Source src)
{
    /* ... whatever ... */
}

But what if the situation instead looked something like this:

shared_ptr<Foo> bar (my_pointer_operator<Foo*>(mumble));

It needs some way to pull the pointer off the type. I dug around and found std::remove_pointer, but a naive application gives a “type/value mismatch”:

template <typename Target, typename Source>
shared_ptr< std::remove_pointer<Target>::type > my_pointer_operator(Source src)
{
    /* ... whatever ... */
}

I didn’t actually expect it to work…but I’m putting it here as an expression of the what-I’m-looking for intent!

Sigh. Every time I step into any new territory with templates and traits I feel like one of those “I have no idea what I’m doing” meme animals. :-/

  • 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-06-06T15:45:03+00:00Added an answer on June 6, 2026 at 3:45 pm

    You need typename:

    template <typename Target, typename Source>
    shared_ptr< typename std::remove_pointer<Target>::type >
        my_pointer_operator(Source src)
    {
        /* ... whatever ... */
    }
    

    Because the type of std::remove_pointer<Target>::type depends on a template argument.

    Personally, I would leave Target as Foo and within the definition of my_pointer_operator use typename std::add_pointer<Target>::type, so the caller can specify the return value more directly. The function name gives away the difference in implementation.

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

Sidebar

Related Questions

I have a snippet of code like this: std::list<boost::shared_ptr<Point> > left, right; // ...
Right now, I have this code: bool isAnyTrue() { for(std::list< boost::shared_ptr<Foo> >::iterator i =
I have code like this: .Where(o => o.Parents.Contains(name)) The above code does not work
I have code like this which opens Word documents for editing from our intranet,
I have code like this: return (new File(pathA + File.separator + pathB + File.separator)).mkdir();
I have code like below, this stored procedure 'get2Rows' returns 2 rows, i want
I have code like this. I click on button and it works only few
I have code like following, it's ok, but I have 2 question about it.
I have code like this: public form() { InitializeComponent(); init(); //read ini and try
I have code like this var MyObj = { f1 : function(o){ o.onmousedown =

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.