Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2007

Tip: Looking for answers? Try searching our database.

Why can't a Dictionary be safe_cast to an Object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave - 16 Oct 2007 14:55 GMT
Why can't I safe_cast a Dictionary to an Object?

Generic::Dictionary<String^, String^> Dict = gcnew
Generic::Dictionary<String^, String^>();
Object^ DictObject = safe_cast<Object ^>(Dict);

Anyone know why the compiler won't handle this syntax?

Dave
Cholo Lennon - 16 Oct 2007 16:05 GMT
> Why can't I safe_cast a Dictionary to an Object?
>
[quoted text clipped - 5 lines]
>
> Dave

You have a mistake in your 'Dict' declaration. You have to declare it like a
managed reference:

Generic::Dictionary<String^, String^>^ Dict = gcnew Generic::Dictionary<String^,
String^>();

Regards

--
Cholo Lennon
Bs.As.
ARG
Dave - 16 Oct 2007 16:35 GMT
Thanks, that fixed it

>> Why can't I safe_cast a Dictionary to an Object?
>>
[quoted text clipped - 20 lines]
> Bs.As.
> ARG
Ben Voigt [C++ MVP] - 16 Oct 2007 17:32 GMT
>> Why can't I safe_cast a Dictionary to an Object?
>>
[quoted text clipped - 13 lines]
> Generic::Dictionary<String^,
> String^>();

This should also work:

Generic::Dictionary<String^, String^> Dict;
Object^ DictObject = %Dict;    // managed address-of -- but managed
deference is still *, not ^ if I remember right

> Regards
>
> --
> Cholo Lennon
> Bs.As.
> ARG

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.