15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Pointer-To-Member-Functions don't work?

Jeff Wishnie -- jwishnie@swellsoft.com
Tuesday, January 23, 1996

I am trying to use pointer-to-member functions to provide a generalized
notification system under VisC++ 4.0 and I am getting incorrect
behavior--essentially the wrong methods are being called AND the "this"
pointer is screwed up when they are called.

I read through the documentation on the compiler and noticed the /vmb, /vmg,
/vmm, /vms, and /vmv switches (represented in DevStudio by the
Pointer-To-Member-Function options on the Build/Settings panel, C++ sheet,
C++ Language Category.

Here's the problem: when I try to recompile with the representation set to
"General Purpose Always", my application hangs. It launches under the
debugger but does not respond to any messages (clicks, keyboard, nothing).

When I recompile with it set back to "Best Case Always", the app executes
but the p-to-member-function calls are incorrect.

Is this a VisC++ bug? Is there a patch?

This is a serious block for me and any help is greatly appreciated.

regards,

Jeff
jwishnie@swellsoft.com
415 552-3125(w)




Bibhas Bhattacharya -- bibhas@hermes
Thursday, January 25, 1996

[Mini-digest: 3 responses]

> 
> I am trying to use pointer-to-member functions to provide a generalized
> notification system under VisC++ 4.0 and I am getting incorrect
> behavior--essentially the wrong methods are being called AND the "this"
> pointer is screwed up when they are called.
> 

A code snippet would have been really useful. If "this" pointer is getting
messed up, go to the line where the function is being invoked (through the
pointer). Check the object for which the function is being invoked.
Atleast, address of that object should be same as "this".

If you're calling the function from a C library make sure that
the object's address is passed as the first argument. (This may not be a
C++ standard).

Bibhas.
bibhas@isgtec.com.

PS: Here is an example,

#include 

//Just a class
class A
{
	int m_i;

public:
    A(int i){m_i = i;}
    void Print();
};

void A::Print()
{
    printf("%d\n", m_i);
}

typedef void (A::*AFunc)(void);

//B stores a pointer of member function of A.
class B
{
	AFunc m_func;
public:
    B(AFunc ap){m_func = ap;}
    void Call(A* a)
    {
	(a->*m_func)(); //Note the parenthesis.
    }
};

main()
{
	A a(10);
	B b(A::Print);

	//Call A::Print for a.
	b.Call(&a);
}
-----From: VARughese GEOrge 


>>I am trying to use pointer-to-member functions to provide a generalized
>>notification system under VisC++ 4.0 and I am getting incorrect
>>behavior--essentially the wrong methods are being called AND the "this"
>>pointer is screwed up when they are called.
if i get it correct, are u trying to do CALLBACK functions using member   
functions.
i hv get solved a similar problem for me. if i am correct, let me know. i   
may be able to help...

thanx
vargeo

-----From: mikeblas@interserv.com

On Tue, 23 Jan 1996, Jeff Wishnie  wrote:
>I am trying to use pointer-to-member functions to provide a generalized
>notification system under VisC++ 4.0 and I am getting incorrect
>behavior--essentially the wrong methods are being called AND the "this"
>pointer is screwed up when they are called.

That's interesting--it seems like something in your build process might be 
wrong.  MFC uses pointers to members very (very) heavily--anything you put 
into a dispatch map, a message map, a parse map, an event map, or an 
interface map involves using pointers to members.

Later, code in whichever part of CCmdTarget (or COleControl, or...) is 
responsible for that sort of mechanism will look up the entry and dispatch a 
call via the pointer to a member function in that entry.

So, either your build process is off, or you're doing something really wierd, 
or you've indeed found a bug.  I'd guess that I listed these here in 
decreasing order of liklihood.

>Is this a VisC++ bug? Is there a patch?

I don't know.  Can you provide a very specific and concise example that 
reproduces the problem you're having?

.B ekiM
--
TCHAR szDisc[] = _T("These words are my own; I don't speak for Microsoft");





| Вернуться в корень Архива |