C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pointer auf Member Funktion

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Sebastian Pasch
Guest





PostPosted: Thu Dec 23, 2004 8:58 am    Post subject: Pointer auf Member Funktion Reply with quote



Hallo
weiß jemand eine Möglichkeit Klassen unabhängige Pointer auf Member
Funktionen zu ermitteln.

class A
{
public:
int Fkt1(int a, int b);
};

class B
{
public:
int Fkt2(int a, int b);
};

class C
{
<Pointer auf Funktion>
public:
void SetCallback(???);

int CallFkt(int a, int b);
};

int main()
{
A a;
B b;
C c;

c.SetCallback(a.Fkt1);
c.CallFkt(0, 0);

c.SetCallback(b.Fkt2);
c.CallFkt(0, 0);

return 0;
}

Der Name der Funktion soll auch unterschiedlich sein können und die
Klassen haben nichts miteinander zutun.

Bei Borland gibt es das Schlüsselwort "closure". Ich arbeite aber mit
dem CodeWarrior für PPC von Metrowerks.

Vielen Dank
Sebastian

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
Back to top
Sebastian Pasch
Guest





PostPosted: Sat Dec 25, 2004 9:15 pm    Post subject: Re: Pointer auf Member Funktion Reply with quote



neatly.
Dredge in flour, eggwash, then seasoned breadcrumbs;
allow to sit for a few minutes.
Sauté in butter and olive oil until golden brown,
about 6 minutes on each side.



Shish Kababes

As old as the hills, this technique has employed seafood, beef, pork, lamb,
poultry, and vegetables; just about anything can be grilled, and young humans
are no exception!

High quality marinade (Teriyaki and garlic perhaps)
1 inch cubes of tender meat, preferably from the nursery
Onions
bell peppers
Wooden or metal skewers

Marinate the meat overnight.
Get the grill good and hot while placing meat, vegetables, and
fruit such as pineapples or cherries on the skewers.
Don?t be afraid to use a variety of meats.
Grill to medium rare,
serve with garlic cous-cous and sautéed asparagus.
Coffee and sherbet for desert then walnuts, cheese, and port.
Cigars for the gentlemen (and ladies if they so desire)!



Crock-Pot Crack Baby

When the quivering, hopelessly addicted crack baby succumbs to death,
get him immediately butchered and into the crock-pot, so that any
remaining toxins will not be fatal. But don?t cook it too long,
because like Blowfish, there is a perfect medium between the poisonous
and the stimulating. Though it may not have the same effect on your
guests, a whole chicken cooked in this fashion is also mighty tasty.

1 newborn - cocaine addicted, freshly expired, cleaned and butchered
Carrots
onions
leeks
celery
bell pepper
potatoes
Salt
pepper
garlic, etc
4 cups water

Cut the meat into natural pieces and brown very well in olive oil,
remove, then brown half of the onions, the bell pepper, and celery.
When brown, mix everythin


Back to top
Sebastian Pasch
Guest





PostPosted: Sat Dec 25, 2004 9:51 pm    Post subject: Re: Pointer auf Member Funktion Reply with quote



Its free, you can sell the crib, baby clothes, toys, stroller... and so easy to
procure if such a lucky find is at hand (just pick him up from the crib and
he?s good to go)!

SIDS victim, cleaned
½ cup cooking oil
Carrots
onions
broccoli
whole cabbage
fresh green beans
potato
turnip
celery
tomato
½ stick butter
1 cup cooked pasta (macaroni, shells, etc.)

Remove as much meat as possible, cube, and brown in hot oil.
Add a little water, season, then add the carcass.
Simmer for half an hour keeping the stock thick.
Remove the carcass and add the vegetables slowly to the stock,
so that it remains boiling the whole time.
Cover the pot and simmer till vegetables are tender
(2 hours approximately).
Continue seasoning to taste.
Before serving, add butter and pasta,
serve piping with hot bread and butter.



Offspring Rolls

Similar to Vietnamese style fried rolls, they have lots of meat
(of course this can consist of chicken, beef, pork, or shrimp).
Who can resist this classic appetizer; or light lunch served with
a fresh salad? Versatility is probably this recipe?s greatest virtue,
as one can use the best part of a prime, rare, yearling, or the
morticians occasional horror: a small miracle stopped short by a
drunk driver, or the innocent victim of a drive-by shooting...

2 cups finely chopped very young human flesh
1 cup shredded cabbage
1 cup bean sprouts
5 sprigs green onion, finely chopped
5 cloves minced garlic
4-6 ounces bamboo shoots
Sherry
chicken broth
oil for deep frying (1 gallon)
Salt
pepper
soy & teriyaki
minced ginger, etc.
1 tablespoon cornstarch dissolved in a little cold water
1 egg be


Back to top
Stefan Reuther
Guest





PostPosted: Sun Dec 26, 2004 5:02 pm    Post subject: Re: Pointer auf Member Funktion Reply with quote

Sebastian Pasch wrote:
Quote:
weiß jemand eine Möglichkeit Klassen unabhängige Pointer auf Member
Funktionen zu ermitteln.
[...]
Bei Borland gibt es das Schlüsselwort "closure". Ich arbeite aber mit
dem CodeWarrior für PPC von Metrowerks.

Es gibt keine genormte Möglichkeit, solche Pointer zu definieren.
Deswegen heißt das Schlüsselwort bei Borland auch normalerweise "__closure".

Du kannst das ganze aber simulieren, z.B.
struct Handler {
virtual void call(int arg) = 0;
};
template<typename T>
struct ClassHandler {
T& object;
void (T::*fun)(int);
ClassHandler(T& object, void (T::*fun)(int))
: object(object), fun(fun) { }
void call(int arg) { (object.*fun)(arg); }
};
und jetzt statt deinem Closure-Zeiger einen 'Handler*'.

Das ganze gibt's verspoilert und verchromt in Boost als Boost.Function /
Boost.Bind.


Stefan

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Marcel Müller
Guest





PostPosted: Mon Dec 27, 2004 12:27 pm    Post subject: Re: Pointer auf Member Funktion Reply with quote

Sebastian Pasch wrote:

Quote:
Hallo
weiß jemand eine Möglichkeit Klassen unabhängige Pointer auf Member
Funktionen zu ermitteln.

Das ist ein Klassiker. Bei Microsoft/C# heißt das delegates. Im Gegensatz zu
Funktionspointern halten die auch das Objekt, auf das sie angewendet
werden sollen.

C++ kann man das (mit ein paar Abstrichen) auch beibringen. Der größte
Nachteil ist eigentlich, daß man für jede Anzahl von Parametern eigene
Klassen braucht.


#include <MMDelegate.h>

Quote:
class A
{
public:
int Fkt1(int a, int b);
};

class B
{
public:
int Fkt2(int a, int b);
};

class C
{
const delegate2_t<int, int, int>* Pointer;
public:
void SetCallback(const delegate2_t<int, int, int>& func)

{ Pointer = &func; }
Quote:

int CallFkt(int a, int b)
{ return (*Pointer)(a,b); }
};

int main()
{
A a;
B b;
C c;

delegateinst2_t<int,A,int,int> da(a, &A::Fkt1);

// Speicherverwaltung ist hier normalerweise erforderlich, da die
Lifetime des
// Delegates an die des Pointers in C geknüpft sein sollte. =>
smart Pointer
c.SetCallback(da);
Quote:
c.CallFkt(0, 0);

delegateinst2_t<int,A,int,int> db(b, &B::Fkt2);

c.SetCallback(db);
Quote:
c.CallFkt(0, 0);

return 0;
}


--- Anhang ---

/*****************************************************************************
*
* MMDelegate.h - delegate implementation
*
* (C) 2003 Marcel Mueller, Fulda, Germany
*
* Freeware
*
****************************************************************************/

/* in contrast to the member function adaptors (e.g. mem_fun_t) delegates
store the object instance in the funcion object. */

template <typename Result>
class delegate_t
{public:
operator()() = 0;
}

template <typename Result, typename X>
class delegateinst_t : delegate_t<Result>
{private:
X* Obj;
Result (X::*Fn)();
public:
delegateinst_t(X* obj, Result (X::*fn)()) : Obj(obj), Fn(fn) {}
Result operator()() { return (Obj->*Fn)(); }
};

template <typename Result, typename Arg>
class delegate1_t
{public:
operator()(Arg) = 0;
}

template <typename Result, typename X, typename Arg>
class delegateinst1_t : delegate1_t<Result, Arg>
{private:
X* Obj;
Result (X::*Fn)(Arg);
public:
delegateinst1_t(X* obj, Result (X::*fn)(Arg)) : Obj(obj), Fn(fn) {}
Result operator()(Arg arg) { return (Obj->*Fn)(arg); }
};

template <typename Result, typename Arg1, typename Arg2>
class delegate2_t
{public:
operator()(Arg1, Arg2) = 0;
}

template <typename Result, typename X, typename Arg1, typename Arg2>
class delegateinst2_t : delegate2_t<Result, Arg1, Arg2>
{private:
X* Obj;
Result (X::*Fn)(Arg1, Arg2);
public:
delegateinst2_t(X* obj, Result (X::*fn)(Arg1, Arg2)) : Obj(obj),
Fn(fn) {}
Result operator()(Arg1 arg1, Arg2 arg2) { return (Obj->*Fn)(arg1,
arg2); }
};

template <typename Result, typename X>
delegateinst_t<Result, X> delegate(X* obj, Result (X::*fn)())
{ return delegateinst_t<Result, X>(obj, fn);
}
template <typename Result, typename X, typename Arg>
delegateinst1_t<Result, X, Arg> delegate(X* obj, Result (X::*fn)(Arg))
{ return delegateinst1_t<Result, X, Arg>(obj, fn);
}
template <typename Result, typename X, typename Arg1, typename Arg2>
delegateinst2_t<Result, X, Arg1, Arg2> delegate(X* obj, Result
(X::*fn)(Arg1, Arg2))
{ return delegateinst2_t<Result, X, Arg1, Arg2>(obj, fn);
}

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Nicolas Pavlidis
Guest





PostPosted: Thu Dec 30, 2004 5:46 pm    Post subject: Re: Pointer auf Member Funktion Reply with quote

Stefan Reuther wrote:

Quote:
Sebastian Pasch wrote:

weiß jemand eine Möglichkeit Klassen unabhängige Pointer auf Member
Funktionen zu ermitteln.

[...]

Bei Borland gibt es das Schlüsselwort "closure". Ich arbeite aber mit
dem CodeWarrior für PPC von Metrowerks.


Es gibt keine genormte Möglichkeit, solche Pointer zu definieren.
Deswegen heißt das Schlüsselwort bei Borland auch normalerweise "__closure".

Du kannst das ganze aber simulieren, z.B.
struct Handler {
virtual void call(int arg) = 0;
};
template<typename T
struct ClassHandler {
T& object;
void (T::*fun)(int);
ClassHandler(T& object, void (T::*fun)(int))
: object(object), fun(fun) { }
void call(int arg) { (object.*fun)(arg); }
};

Mir kommt vor, das du beim ClassHandler ein : public Handler vergessen
hast, also:
template struct ClassHandler : public Handler
{
//....
};

Oder habs du was anderes gemeint?

LG
Nicolas

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Nicolas Pavlidis
Guest





PostPosted: Thu Dec 30, 2004 5:49 pm    Post subject: Re: Pointer auf Member Funktion Reply with quote

Marcel Müller wrote:

Quote:
Sebastian Pasch wrote:

Hallo
weiß jemand eine Möglichkeit Klassen unabhängige Pointer auf Member
Funktionen zu ermitteln.


Das ist ein Klassiker. Bei Microsoft/C# heißt das delegates. Im Gegensatz zu
Funktionspointern halten die auch das Objekt, auf das sie angewendet
werden sollen.

C++ kann man das (mit ein paar Abstrichen) auch beibringen. Der größte
Nachteil ist eigentlich, daß man für jede Anzahl von Parametern eigene
Klassen braucht.

Eine weitere Moeglichkeit waere Loki::Functor. Auch wenn der dort
Typelists verwendet.
Das ganze wird allerdings dann problematisch, wenn man viele Callbacks
mit verschiedenen Parametersaetzen braucht, und dese irgendwo
registriert werden muessen, sonst nimmt diese Klasse einem viel Arbeit
ab *schwaerm* Smile.

LG
Nicolas

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Stefan Reuther
Guest





PostPosted: Thu Dec 30, 2004 7:38 pm    Post subject: Re: Pointer auf Member Funktion Reply with quote

Nicolas Pavlidis wrote:
Quote:
Stefan Reuther wrote:
template struct ClassHandler {

Mir kommt vor, das du beim ClassHandler ein : public Handler vergessen
hast, also:
template struct ClassHandler : public Handler

Du hast recht. Danke.


Stefan

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.