CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2006
    Location
    Chile
    Posts
    13

    Arrow What depa is this ?

    I have a pattern question
    Code:
    class A
    {
    public:
        T a1;
        T a2;
        void funcA()
       {
           //Initialize a1,a2
       }
    };
    
    class B
    {
    public:
        T a1;
         void Do_a1(){}
    };
    
    class C
    {
    public:
        T a2;
         void Do_a2(){}
    
    };
    
    
    // in main
    A a;
    a.funcA();
    //assign a1, a2 of A for B's a1 and C's a2
    //then call Do_a1, Do_a2;
    THat is the idea, and I'd like to know what pa is most same as it. Thanks a lot for help
    Pumpobee is prolounced as mumbolee

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: What depa is this ?

    I don't follow what you are asking.
    What is pa?
    What exactly you want to do?
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: What depa is this ?

    Quote Originally Posted by Marc G View Post
    I don't follow what you are asking.
    What is pa?
    I guess it's the tail of "depa" from the subject...
    But I could be wrong!
    Victor Nijegorodov

  4. #4
    Join Date
    Jan 2009
    Posts
    596

    Re: What depa is this ?

    I guess, from the context, depa means design pattern. Never heard this abbreviation before, though...

  5. #5
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: What depa is this ?

    I don't see any design pattern in that piece of code.
    The classes A, B, and C are completely separated.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: What depa is this ?

    Something like this: (though it's not a pattern )
    Code:
    template <typename T>
    class A
    {
    public:
        void funcA1()
       {
       	T* pThis = static_cast<T*>(this);
           //Initialize a1
           //pThis->a1 something...
       }
        void funcA2()
       {
       	T* pThis = static_cast<T*>(this);
           //Initialize a2
           //pThis->a2 something...
       }
    };
    
    class T
    {
    public:
        T() {}
    };
    
    class B: public A<B>
    {
    public:
        T a1;
         void Do_a1(){}
    };
    
    class C: public A<C>
    {
    public:
        T a2;
         void Do_a2(){}
    
    };
    
    int main()
    {
    // in main
    //assign a1, a2 of A for B's a1 and C's a2
    //then call Do_a1, Do_a2;
    
    	B b;
    	b.funcA1();
    	b.Do_a1();
    
    	C c;
    	c.funcA2();
    	c.Do_a2();
    
    	return 0;
    }
    Last edited by Igor Vartanov; November 18th, 2011 at 04:14 AM.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured