Why can't a Dictionary be safe_cast to an Object

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

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
 
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

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
 
Thanks, that fixed it

Cholo Lennon said:
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 said:
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^>();

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
 
Back
Top