Re: CListBoxGetItemDataPtr and dynamic cast
Hi G,
I think what Joe is saying is that you can override the function to return
the right kind of pointer then you don't have to fool with it. That works,
of course, if you intend to use the list box only for one kind of pointer.
When I do this sort of thing I tend to make another structure that has a:
type
pointer to data
That way if I want to have more than one type of data (depending on the item
in the list box or list control or tree control) I can check the type before
casting. You could do this in the overridden functions and just have one
for each type you intend to return.
Tom
"Giovanni Dicanio" <giovanni.dicanio@invalid.it> wrote in message
news:uFpddJNNIHA.280@TK2MSFTNGP03.phx.gbl...
"Joseph M. Newcomer" <newcomer@flounder.com> ha scritto nel messaggio
news:9k64l3dgmr5dtfl3cc65t3s67lh2rjp48d@4ax.com...
It probably would have been better if these methods had been virtual, but
in the interest
of "efficiency" they are not.
I see no reason to have stored it in a void *.
Hi Joe,
I may be missing something, but I think that using 'virtual' in this
context would not be of important help.
The problem here is the type of the return value. If you have a method
declared as virtual, this does not help much.
The help that virtual gives is when you want to use polymorphism and
pointers, e.g.
class Base
{
...
public:
virtual void * GetSomething();
};
class Derived : public Base
{
...
public:
virtual void * GetSomething();
};
And so if you have:
Base * p = new Derived();
p->GetSomething();
then Derived::GetSomething() is called (and not Base::GetSomething).
I think that using templates would have helped better (because the return
type can be made a template type), but I see several problems when I try
to mix templates and MFC... for example, for message maps.
What do you think about this (templates and MFC) ?
Thanks,
Giovanni