Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » C++

Is there a solution to that?

 
Jump to:  
 
Guest
PostPosted: Thu Sep 04, 2008 7:38 pm    Post subject: Is there a solution to that?
       
I need a construct that allows definition of incomplete class (both
methods and fields might me missing) and
it allows to Mix them (symmetrical, associative binary operator).
The incomplete classes should be able to call methods of each other
with zero run-time cost.
Do you know any C++ library that achieves that or something similar?

Also I think it's much more useful than normal inheritance. But I
guess I'm wrong. :)


Regards
Lukasz
PS
Here is my implementation of that, construct.
Do you have any idea how to simplify it?
I could use some critics Smile
#define BEGIN_MIXIN(Name) \
struct Name { template <class Final> class Mixin { \
Final& final () { return static_cast<Final&> (*this); } \
public:

#define END_MIXIN };};

template<class Mixin1, class Mixin2>
class Mix {
public:
template <class Final> class Mixin
: public Mixin1::template Mixin<Final>,
public Mixin2::template Mixin<Final>
{ };
};

template < class Mixin > class Final
: public Mixin::template Mixin< Final<Mixin> > {};


// -----------------------------------------------------------
// Example:

#include <iostream>
//#include "mixins"

using namespace std;

BEGIN_MIXIN(B)
void f () {
cout << "Hello ";
final ().g();
}
END_MIXIN

BEGIN_MIXIN(A)
void g () { cout << "World !" << endl; }

void test_run () { final().f(); }
END_MIXIN

BEGIN_MIXIN(S)
void s () { cout << "Single !" << endl; }
END_MIXIN


int main () {
Final<Mix<A ,Mix<B,S> > > mixed_object;;
mixed_object.test_run ();
mixed_object.s();
return 0;
}

--
[ See LINK for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

zabawki edukacyjne baseny Ogrody rowery Agencja interaktywna