| | | Guest |  |
| Posted: 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  #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! ] |
|