C2682: cannot use __try_cast to convert from 'gcroot<T>' 
Author Message
 C2682: cannot use __try_cast to convert from 'gcroot<T>'

Hello All,
I have a standard C++ class with MC++ member defined as

gcroot<System::Drawing::Brush __gc*> m_pDotNetBrush;

Somewhere in the codes, I wish to use the brush and trying to
cast it to the appropriate type:

    System::Drawing::SolidBrush __gc* pBrush =
     __try_cast<System::Drawing::SolidBrush __gc*>(m_pDotNetBrush);

This, however, generates error in the form:

error C2682: cannot use __try_cast to convert from 'gcroot<T>' to
'System::Drawing::SolidBrush __gc *'

I tried the other standard C++ casts and all failed with same error.
What is supposed to be done in this case?

Best regards,
Paul.



Sat, 17 Sep 2005 15:49:28 GMT  
 C2682: cannot use __try_cast to convert from 'gcroot<T>'

Quote:

> gcroot<System::Drawing::Brush __gc*> m_pDotNetBrush;

> Somewhere in the codes, I wish to use the brush and trying to
> cast it to the appropriate type:

>     System::Drawing::SolidBrush __gc* pBrush =
>      __try_cast<System::Drawing::SolidBrush __gc*>(m_pDotNetBrush);

> This, however, generates error in the form:

Normaly you should do:

System::Drawing::Brush *b;
b = m_pDotNetBrush;

Then you can try to cast it...

System::Drawing::SolidBrush *pBrush =
  __try_cast<System::Drawing::SolidBrush*>(b);

--
Greetings
  Jochen

  Do you need a memory-leak finder ?
  http://www.codeproject.com/useritems/leakfinder.asp



Sat, 17 Sep 2005 16:04:40 GMT  
 C2682: cannot use __try_cast to convert from 'gcroot<T>'
Hello Jochen,
Thanks so much, it worked.

Best regards,
Paul.


Quote:

> > gcroot<System::Drawing::Brush __gc*> m_pDotNetBrush;

> > Somewhere in the codes, I wish to use the brush and trying to
> > cast it to the appropriate type:

> >     System::Drawing::SolidBrush __gc* pBrush =
> >      __try_cast<System::Drawing::SolidBrush __gc*>(m_pDotNetBrush);

> > This, however, generates error in the form:

> Normaly you should do:

> System::Drawing::Brush *b;
> b = m_pDotNetBrush;

> Then you can try to cast it...

> System::Drawing::SolidBrush *pBrush =
>   __try_cast<System::Drawing::SolidBrush*>(b);

> --
> Greetings
>   Jochen

>   Do you need a memory-leak finder ?
>   http://www.codeproject.com/useritems/leakfinder.asp



Sat, 17 Sep 2005 20:01:30 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Error error C2440: '=' : cannot convert from

2. 'mem_fun' : cannot convert parameter 1

3. <<<<<<<Parsing help, please>>>>>>>>

4. Warning C4244 with gcroot<>

5. File Format conversion, ascii freeform -->.csv <-->.wk1<-->dbf<-->?HELP

6. <<<>>>Need C code advice with functions and sorting.<<<>>>

7. <><><>HELP<><><> PCMCIA Motorola Montana 33.6

8. Dos and don'ts for people with hook-hands covered in tabasco sauce

9. Friend and '<<' overloading

10. 'operator <<' is ambiguous error

11. Procedure Reference problem - cannot convert from 'ref System.Windows.Forms.Data

12. >>>Windows Service<<<

 

 
Powered by phpBB® Forum Software