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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:47:31+00:00 2026-05-23T17:47:31+00:00

I am designing a template class Policy which needs to be able to handle

  • 0

I am designing a template class Policy which needs to be able to handle pointers to other classes.

template <class P>
class Policy
{
  private:   
    const P *state;
  public:
    Policy (P const* s) : state(s){};
};

This works fine.
Now I want to inherit from the above template class and create new subclasses:

class Greedy : public Policy<???>
{
  public:
    template <typename P> Greedy (P const* s) : Policy(s) {}:
};

class Explora : public Policy<???>
{ 
  public:
    template <typename P> Explora (P const* s) : Policy(s) {}:
};

Problem is that when defining those classes I do not know what type they will be using for the base template class. Is this even possible to do ?
I want the type obtained from the inherited class constructor (probably templated), and then pass it to the base class construtor.
Can I do that ? If yes, how ? typedefining enums ?
I have seen this question but it doesn’t in my opinion really answer the question.

  • 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-23T17:47:32+00:00Added an answer on May 23, 2026 at 5:47 pm

    Make them template classes:

    template <typename P>
    class Greedy : public Policy<P>
    {
        // now you know
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given class Foo template <typename T> class Foo { public: ...other methods.. void bar()
I am designing class, which is almost the same for 2d and 3d, so
I'm trying to do a base template class which parameter T must be a
I've a class Foo<T> which has a vector of smart pointers to Shape derived
template <class T> class Test { public: template<class U> void f(); //generic function template<>
Possible Duplicate: What is the difference between "typename" and "class" template parameters? When defining
When designing LINQ classes using the LINQ to SQL designer I've sometimes needed to
When designing a collection class, is there any reason not to implement locking privately
I'm in the process of designing several classes that need to support operators !=
Imagine the following template class (setter and getter for the member _t omitted): template<class

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.