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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:05:36+00:00 2026-06-13T03:05:36+00:00

Let me show several classes firstly: class globalcontext { public: /*partA context*/ A; B;

  • 0

Let me show several classes firstly:

class globalcontext
{
  public:
  /*partA context*/
  A;
  B;
  c;
  /*partB context*/
  D;
  E;
  F;
  .......
  execute();  //a method to do something (serialize) for context above

};

class mainprocess
{
     callsubprocess();
};
class subprocessA{};
class subprocessB{};
class subprocessC{};
..................

Actually, there are several backends running the main process, so the context will be sent from here or there, that’s why I want to execute(serialize/unserialize).

The flow is like: mainprocess::callsubprocess() —-> choose a subprocess, so choose subprocessA—-> execute partA of context from globalcontext class.

Is it possible to use factory in boost?

  • 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-13T03:05:37+00:00Added an answer on June 13, 2026 at 3:05 am

    Maybe you are looking for a strategy pattern? Assuming that A-F encode behaviour, you could ‘mixin’ different behaviours or supply them as strategies:

    Note: below, the separation between static/non-static member functions is a little bit arbitrary (mixins can perfectly well contain static members).

    Mixins

    #include <iostream>
    
    struct NormalPartABehaviour {
        void A() { std::cout << "Normal A" << std::endl; }
        void B() { std::cout << "Normal B" << std::endl; }
        void C() { std::cout << "Normal C" << std::endl; }
    };
    
    struct SpecialPartABehaviour {
        void A() { std::cout << "Special A" << std::endl; }
        void B() { std::cout << "Special B" << std::endl; }
        void C() { std::cout << "Special C" << std::endl; }
    };
    
    struct NormalPartBBehaviour {
        void D() { std::cout << "Normal D" << std::endl; }
        void E() { std::cout << "Normal E" << std::endl; }
        void F() { std::cout << "Normal F" << std::endl; }
    };
    
    template <typename PartAMixin, typename PartBMixin>
    struct GlobalContext : public PartAMixin, public PartBMixin
    {
    };
    
    ///// test method:
    
    template <class Context>
    void test(Context globalcontext)
    {
        globalcontext.A();
        globalcontext.B();
        globalcontext.C();
        globalcontext.D();
        globalcontext.E();
        globalcontext.F();
    }
    
    int main()
    {
        GlobalContext<NormalPartABehaviour,  NormalPartBBehaviour> ctx1;
        GlobalContext<SpecialPartABehaviour, NormalPartBBehaviour> ctx2;
    
        std::cout << "testing ctx1: \n";
        test(ctx1);
        std::cout << "testing ctx2: \n";
        test(ctx2);
    }
    

    Output http://liveworkspace.org/code/b6b5cfffba11df68bc70c432b030b1d5

    testing ctx1:
    Normal A
    Normal B
    Normal C
    Normal D
    Normal E
    Normal F
    testing ctx2:
    Special A
    Special B
    Special C
    Normal D
    Normal E
    Normal F
    

    Strategy

    #include <iostream>
    
    struct NormalPartABehaviour {
        static void A() { std::cout << "Normal A" << std::endl; }
        static void B() { std::cout << "Normal B" << std::endl; }
        static void C() { std::cout << "Normal C" << std::endl; }
    };
    
    struct SpecialPartABehaviour {
        static void A() { std::cout << "Special A" << std::endl; }
        static void B() { std::cout << "Special B" << std::endl; }
        static void C() { std::cout << "Special C" << std::endl; }
    };
    
    struct NormalPartBBehaviour {
        static void D() { std::cout << "Normal D" << std::endl; }
        static void E() { std::cout << "Normal E" << std::endl; }
        static void F() { std::cout << "Normal F" << std::endl; }
    };
    
    template <typename PartAMixin, typename PartBMixin>
    struct GlobalContext
    {
        static void A() { PartAMixin::A(); }
        static void B() { PartAMixin::B(); }
        static void C() { PartAMixin::C(); }
    
        static void D() { PartBMixin::D(); }
        static void E() { PartBMixin::E(); }
        static void F() { PartBMixin::F(); }
    };
    
    ///// test method:
    
    template <class Context>
    void test()
    {
        Context::A();
        Context::B();
        Context::C();
        Context::D();
        Context::E();
        Context::F();
    }
    
    int main()
    {
        typedef GlobalContext<NormalPartABehaviour,  NormalPartBBehaviour> ctx1;
        typedef GlobalContext<SpecialPartABehaviour, NormalPartBBehaviour> ctx2;
    
        std::cout << "testing ctx1: \n";
        test<ctx1>();
        std::cout << "testing ctx2: \n";
        test<ctx2>();
    }
    

    Output http://liveworkspace.org/code/8bca96d0e9784026c6357a30110bc5fd

    testing ctx1: 
    Normal A
    Normal B
    Normal C
    Normal D
    Normal E
    Normal F
    testing ctx2: 
    Special A
    Special B
    Special C
    Normal D
    Normal E
    Normal F
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say i have several div's like these: EDIT: <div class=ProfilePic> <a href=#> <img
Let me show what I need first so you can understand my problem. I
I am having a difficult time sorting through this PHP/MySQL issue. Let me show
a funny problem ... i can't understand it.. let me show you what i
I have a few weird issues I need to solve. First, let me show
I want to let a div show and disappaer with jquery and css. The
Specifically how can I: Show a button which will let the user browse through
Let's say that I have an application frame, and I want to show a
I can't seem to find anything that would let me to easily show a
For this question, let us assume that we will want to show the face

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.