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

The Archive Base Latest Questions

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

As a simplified example, if I have the classes template <class T, class U>

  • 0

As a simplified example, if I have the classes

template <class T, class U> class ProcessEvent
{
  public:
    ProcessEvent(T* t) : var1(t) { var2 = new U; }
    Process() { var2->Process(var1); }
  private:
    T* var1;
    U* var2;
};

class Foo 
{
  /*data*/
};

class FooProcessor 
{
  void Process(Foo* foo) {/*functionality*/}
};

class Bar
{
  /*data*/
};

class BarProcessor 
{
  void Process(Bar* bar) {/*functionality*/}
};

So the class ProcessEvent can take have two different sets of template types,

ProcessEvent<Foo, FooProcessor>
ProcessEvent<Bar, BarProcessor> 

However, the second template type FooProcessor and BarProcessor are directly implied by the first template type and are implementation details the user doesn’t care about. My goal is to have the same functionality as above, but have ProcessEvent take only a single template parameter, Foo or Bar. Other than through specialization of ProcessEvent, can this be done?

  • 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-29T09:01:33+00:00Added an answer on May 29, 2026 at 9:01 am

    You can do this as follows:

    template<typename T>
    class Spec 
    {
    };
    
    template<>
    class Spec<Foo>
    {
       typedef FooProcessor type;
    };
    
    template<>
    class Spec<Bar>
    {
       typedef BarProcessor type;
    };
    

    Then use Spec<T>::type, with T=Bar or T=Foo, whenever you need BarProcessor and FooProcessor, respectively.

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

Sidebar

Related Questions

As a simplified example, I have the following data classes: public class Employee {
I have the following classes, they are bit simplified for example. class LineInfo {
I have 3 classes (simplified for this question): public class Page { public Guid
I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
So say, for example I have two classes: Base = declarative_base() class Vendor(Base): __tablename__
I have data model classes that contain private fields which are meant to be
Let's consider following, simplified example: We have 2 tabs withing <rich:tabPanel switchType=ajax> , each
Simplified for example, I have two tables, groups and items . items ( id,
I've simplified this example as much as I can. I have a remote function:
This is a simplified example to illustrate the question: class A {}; class B

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.