Re: Static member functions in VC
From: Gnum (no-email_at_mail.boo)
Date: 05/11/04
- Previous message: Gnum: "Re: Static member functions in VC"
- In reply to: Doug Harrison [MVP]: "Re: Static member functions in VC"
- Next in thread: Doug Harrison [MVP]: "Re: Static member functions in VC"
- Reply: Doug Harrison [MVP]: "Re: Static member functions in VC"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 12 May 2004 09:20:01 +1200
You're right of course.
What I want to achieve is NON static member function to be assigned as
Callback procedure.
It is exactly right that it HAS TO contain pointer to an object itself.
One again you're right it is NOT standard C++ pointer as it is implemented
in Borland C++ Builder by special way as Igor Tandetnik suggested here.
And you're right it is like .Net delegate.
My question was HOW TO say VC++ to handle it with no requiring me to write
fancy macros and handle it manually.
I do know how to do it, but I don't want to waste my time before I ensure
there is no other way around.
By the way. Thank you all guys! Now i know that I HAVE TO handle it bymeself
as Microsoft hasn't implemented any common solution of this problem in VC++
6.0 OR it is hidden so far that I will never know about it.
Cheers!
Gnum
"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message
news:0jb2a0tkvtb3u4uucv5ndn5n37apq23d31@4ax.com...
> Gnum wrote:
>
> >I've got a problem:
> >
> >====================================================
> >typedef void FOnEven( int );
> >
> >class clsA
> >{
> >private:
> >public:
> > FOnEven* OnEvent;
> >};
> >
> >class clsB
> >{
> >private:
> > clsA* A;
> >public:
> > clsB();
> > static void Event( void );
> >}
> >
> >clsB::clsB()
> >{
> > A = new clsA();
> > A->OnEvent = Event;
> >}
> >
> >void clsB::Event( void )
> >{
> > From inside this function I can't see Data members of the object as
> ><this> point is not defined here.
> > However in Borland C++ Builder this construction allows me to see
them.
>
> That can't be. The "this" pointer is not available inside static member
> functions like "Event". Period. Mario gave you one possible workaround.
>
> > I can't realize how to implement the same ability in MS Visual C++.
> > I don't want to write long tricky and looking weird things to get
around
> >this restriction to assign
> > only STATIC functions pointers to variables like my FOnEven* OnEvent;
> >
> > Does anyone know some general solution?
> > I wish there was a tickbox in settings to say "Allow assign NOT
STATIC
> >member functions to CALLBACKs"
> >}
>
> Are you sure you're not confusing normal function pointers with pointers
to
> (non-static) member functions? Normal C++ pointers to members don't
contain
> an instance pointer. However, you can create a class that encapsulates an
> instance pointer and a pointer to member function, which would then be
much
> like a .NET delegate. Maybe C++ Builder provides something like that? If
so,
> then your "Event" function would be a non-static member function.
>
> --
> Doug Harrison
> Microsoft MVP - Visual C++
- Previous message: Gnum: "Re: Static member functions in VC"
- In reply to: Doug Harrison [MVP]: "Re: Static member functions in VC"
- Next in thread: Doug Harrison [MVP]: "Re: Static member functions in VC"
- Reply: Doug Harrison [MVP]: "Re: Static member functions in VC"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|