From: Vaclav on
Hello,

I am trying to get a pointer stored in a CListBox item.


int li_index = m_lineTypesListBox.GetCurSel();
if (LB_ERR == li_index)
{
return 0;
}

void* pItem = m_lineTypesListBox.GetItemDataPtr(li_index);
QLin* pLin = dynamic_cast<QLin*>(pItem);


Getting
error C2681: 'void *' : invalid expression type for dynamic_cast


Thanks
Vaclav


From: Tom Serface on
I'm guessing that you're getting this error since the listbox is returning a
void * which is not related to a QLin *. I would try reinterpret_cast or
just saying

QLin* pLin = (QLin*)pItem;

Tom

"Vaclav" <vjedlicka(a)atlas.cz> wrote in message
news:uB1TA6ANIHA.4880(a)TK2MSFTNGP03.phx.gbl...
> Hello,
>
> I am trying to get a pointer stored in a CListBox item.
>
>
> int li_index = m_lineTypesListBox.GetCurSel();
> if (LB_ERR == li_index)
> {
> return 0;
> }
>
> void* pItem = m_lineTypesListBox.GetItemDataPtr(li_index);
> QLin* pLin = dynamic_cast<QLin*>(pItem);
>
>
> Getting
> error C2681: 'void *' : invalid expression type for dynamic_cast
>
>
> Thanks
> Vaclav
>

From: Giovanni Dicanio on

"Vaclav" <vjedlicka(a)atlas.cz> ha scritto nel messaggio
news:uB1TA6ANIHA.4880(a)TK2MSFTNGP03.phx.gbl...

> I am trying to get a pointer stored in a CListBox item.

> void* pItem = m_lineTypesListBox.GetItemDataPtr(li_index);
> QLin* pLin = dynamic_cast<QLin*>(pItem);

You might want to use a C++ reinterpret_cast, or just C-style casts, e.g.:

QLin * pLin = reinterpret_cast<QLin*>( pItem );

or

QLin * pLin = (QLin *)pItem;

G


From: Giovanni Dicanio on
Ops, Tom: sorry if I answered again...
(Your post did not appear on my Outlook when I sent mine)

G


"Tom Serface" <tom.nospam(a)camaswood.com> ha scritto nel messaggio
news:1522916F-602D-4ED7-96A2-5EBF78CF9D4A(a)microsoft.com...
> I'm guessing that you're getting this error since the listbox is returning
> a void * which is not related to a QLin *. I would try reinterpret_cast
> or just saying
>
> QLin* pLin = (QLin*)pItem;
>
> Tom
>
> "Vaclav" <vjedlicka(a)atlas.cz> wrote in message
> news:uB1TA6ANIHA.4880(a)TK2MSFTNGP03.phx.gbl...
>> Hello,
>>
>> I am trying to get a pointer stored in a CListBox item.
>>
>>
>> int li_index = m_lineTypesListBox.GetCurSel();
>> if (LB_ERR == li_index)
>> {
>> return 0;
>> }
>>
>> void* pItem = m_lineTypesListBox.GetItemDataPtr(li_index);
>> QLin* pLin = dynamic_cast<QLin*>(pItem);
>>
>>
>> Getting
>> error C2681: 'void *' : invalid expression type for dynamic_cast
>>
>>
>> Thanks
>> Vaclav
>>
>


From: Joseph M. Newcomer on
Typically, I just subclass the listbox and create a method

QLin * GetItemDataPtr(int n) { return (QLin*)CListBox::GetItemDataptr(n); }

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 *.
joe

On Sat, 1 Dec 2007 12:37:08 +0100, "Vaclav" <vjedlicka(a)atlas.cz> wrote:

>Hello,
>
>I am trying to get a pointer stored in a CListBox item.
>
>
> int li_index = m_lineTypesListBox.GetCurSel();
> if (LB_ERR == li_index)
> {
> return 0;
> }
>
> void* pItem = m_lineTypesListBox.GetItemDataPtr(li_index);
> QLin* pLin = dynamic_cast<QLin*>(pItem);
>
>
>Getting
>error C2681: 'void *' : invalid expression type for dynamic_cast
>
>
>Thanks
>Vaclav
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm