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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:16:48+00:00 2026-05-20T20:16:48+00:00

First something that should work, then something that doesn’t. Why doesn’t it is the

  • 0

First something that should work, then something that doesn’t. Why doesn’t it is the question.

I declare two classes:

class Base { ... };
class Derived : public Base { ... };

I then have the following function elsewhere:

void foo(shared_ptr<Base> base);   

The following code should work right?

share_ptr<Derived> derived;
foo(derived);

Now, forget the above, I declare three classes:

class Foo { ... };
template <typename TYPE> class Base { ... };
class Derived : public Base<Foo> { ... };

Elsewhere, I declare a templated function:

template <typename TYPE> void foo(shared_ptr<Base<TYPE> > base); 

The following code does not work:

shared_ptr<Derived> derived;
foo(derived);

It says that there is no matching function foo(…) found which accepts share_ptr<Derived>

First, should the original example work? And second, what do you think could be the issue in the second example where I have a shared_ptr to a class that is derived from a specialized base class.

  • 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-20T20:16:48+00:00Added an answer on May 20, 2026 at 8:16 pm

    I don’t think the compiler will go through a level of indirection in that way. Rather, you can explicitly instantiate foo with TYPE set to Foo. Eg, the following compiles via g++:

    #include<boost/shared_ptr.hpp>
    
    class Foo {};
    template <typename T> class Base {};
    class Derived : public Base<Foo> {};
    
    template<typename T>
    int foo(boost::shared_ptr<Base<T> > base) {return 0;}
    
    boost::shared_ptr<Derived> derived;
    int t = foo<Foo>(derived);
    
    int main() {return 0;}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The first one is definitely something that works, but which one below is the
I am trying to write my first real python function that does something real.
When are objects or something else said to be "first-class" in a given programming
I have two html pages, when you click on something on the first html,
I'm trying out my first Spring project and must be doing something really stupid
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
First off, I understand the reasons why an interface or abstract class (in the
I'm looking for a voting system that we can implement at work amongst our
First of all, I would like to say that I have used the search
Let's assume we are designing a Stack class test-first (TDD): public class Stack<T> {

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.