Re: static member function wrapper
From: Josh Sebastian (curien_at_cox.net)
Date: 11/11/03
- Next message: Steven O.: "User-Friendly GUI Builder in C++?"
- Previous message: Stefan Höhne: "Re: Marshalling Message??"
- In reply to: forums_mp: "Re: static member function wrapper"
- Next in thread: Josh Sebastian: "Re: static member function wrapper"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 11 Nov 2003 10:11:06 -0500
On Mon, 10 Nov 2003 18:57:38 -0800, forums_mp wrote:
> Josh Sebastian <curien@cox.net> wrote in message news:<pan.2003.11.10.23.03.01.619671@cox.net>...
>> On Mon, 10 Nov 2003 14:57:27 -0800, forums_mp wrote:
>>
>> > typedef void (TEST::*FUNCPTR)();
>> >
>> > static int TaskMain(TEST* obj, FUNCPTR p)
>> > {
>> > //(obj->(*p)()); // doesnt work .
>> > // p is of type int also not good ?
>>
>> ITYM
>>
>> obj->*p();
>>
>> No, they're not the same: ->* is a single operator.
>
> I was perusing one of my books in an attempt to understand this
> syntax. I could see we're trying to access a member function using a
> pointer but I'm at a loss on how this becomes a single operator.
>
> Greatly appreaciate the insight considering i was able to get
> something to work but here again I improve test code but dont think i
> full understand
> this
>
> (obj->*(obj->pFunc))();
>
>
> obj->pFunc = address of representative function
Address of a member function, yes.
> *(obj->pFunc) = deferenced or ...?
No.
obj->*x
x is a pointer-to-member. The result is the member of obj that x points
to. In your example, x is a little complex, but the same idea applies.
> argument list () works outside ...
And the () function-call-operator invokes the function.
> trying to work through the syntax but as with most things mine here is
> a case of confusion ..
>
>
>
> class TEST
> {
> private:
> int spawned;
> static int bogus; // how would i initialize bogus
Outside the class, do
int TEST::bogus = 42;
No, it doesn't matter that bogus is private.
> public:
> typedef void (TEST::*TESTPTR)();
>
> TESTPTR pFunc;
>
> TEST(TESTPTR func) : spawned(0), pFunc(func)
> {
> std::cout << " Constructor called " << std::endl;
> TEST::TaskMain(this);
> }
> ~TEST() { std::cout << " Destructor called " << std::endl; }
>
> static int TaskMain(TEST* obj)
> {
> (obj->*(obj->pFunc))(); // works but not really following
> this syntax
Well, how about this (which is equivalent):
TESTPTR tp = obj->pFunc;
obj->*tp();
Does that make it clearer?
> return 0;
> }
> void StartA() { std::cout << " A Started " << std::endl; }
> void StartB() { std::cout << " B Started " << std::endl; }
> void StartC() { std::cout << " C Started " << std::endl; }
> };
>> Josh
- Next message: Steven O.: "User-Friendly GUI Builder in C++?"
- Previous message: Stefan Höhne: "Re: Marshalling Message??"
- In reply to: forums_mp: "Re: static member function wrapper"
- Next in thread: Josh Sebastian: "Re: static member function wrapper"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|