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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:45:49+00:00 2026-06-16T17:45:49+00:00

Executor class has template of type P and it takes a P object in

  • 0

Executor class has template of type P and it takes a P object in constructor. Algo class has a template E and also has a static variable of type E. Processor class has template T and a collection of Ts.

Question how can I define Executor< Processor<Algo> > and Algo<Executor> ? Is this possible? I see no way to defining this, its kind of an “infinite recursive template argument”

See code.

template <class T>
class Processor { 
    map<string,T> ts;
    void Process(string str, int i)
    {
        ts[str].Do(i);
    }
} 

template <class P>
class Executor {
    P &p;
    Executor(P &inp) : p(inp) {}

    void Bar(string str, int i) {
        p.Process(str,i);
    }

    Execute(string str)
    {
    }
} 

template <class E>
class Algo
{
    static E e;

    void Do(int i) {}
    void Foo()
    {
        e.Execute("xxx");
    }
}

main ()
{
    typedef Processor<Algo> PALGO; // invalid
    typedef Executor<PALGO> EPALGO;
    typedef Algo<EPALGO> AEPALGO;

    Executor<PALGO> executor(PALGO());
    AEPALGO::E = executor;
}

EDIT ****************************

A little clarification. Executor is a singleton that provides a service. All Algo objects need the services of Executor. Executor will sometimes generate reports that need to be sent to a specific Algo object. They get sent to the correct Algo through Processor.

Basic issue is that Algo is needed to define Executor and Executor is needed to define Algo.

  • 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-16T17:45:51+00:00Added an answer on June 16, 2026 at 5:45 pm

    Solved! see comments. //****

    #include <string>
    #include <map>
    #include <iostream>
    using namespace std;
    
    template <class T>
    class Processor {
    public:
        map<string,T*> ts;
        void Process(string str, int i)
        {
            ts[str]->Do(i);
        }
    };
    
    template <class P>
    class Executor  {
    public:
        P &p;
        Executor(P &inp) : p(inp) {}
    
        void Bar(string str, int i) {
            p.Process(str,i);
        }
    
        void Execute(string str)
        {
            cout << " Executor::Execute " << str << endl;
        }
    };
    
    template <template <class> class E> //**********
    class Algo
    {
        string str;
    public:
        Algo(const string &s) : str(s) {}
    
        static E<Processor<Algo>> *e; //**********
    
        void Do(int i) { cout << str << "::Do(" << i <<")"<< endl; }
    
        void Foo()
        {
            e->Execute(str);
        }
    };
    
    template <template <class> class E>
    E< Processor<Algo<E> > >* Algo<E>::e;  //**********
    
    int main(int argc, char **argv)
    {
        typedef Algo<Executor> EALGO;
        typedef Processor<EALGO> PALGO;
        typedef Executor<PALGO> EPALGO;
    
        PALGO p;
        EPALGO executor(p);
    
        EALGO::e = &executor; //**********
    
        EALGO ealgo1("algo1"), ealgo2("algo2");
    
        p.ts["algo1"] = &ealgo1;
        p.ts["algo2"] = &ealgo2;
        ealgo1.Foo();
        ealgo2.Foo();
        executor.Bar("algo1",1111);
        executor.Bar("algo2",2222);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is the code snippet. @Intercepts({@Signature( type= Executor.class, method = update, args = {MappedStatement.class,Object.class})})
Sample code: public class ThreadTest{ public static void main(String ...arg){ try{ ExecutorService executor =
I have a simple class that has a property called executor in which I'd
What the right way to interrupt executor's thread? I've got this: Thread class with
I'm trying to write a multithreaded web crawler. My main entry class has the
I'm using a thrid-party lib that has a static synchronized method, i want to
I've the following class. It has the code to connect to SAP in its
Given the following code: public class FooBar { public static volatile ConcurrentHashMap myConfigData =
When creating an FixedThreadPool Executor object in Java you need to pass an argument
The ThreadPoolExecutor class in the Java SE 6 docs has the following method :

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.