[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
A ref class is a user-defined class that can be passed across the ABI boundary.
The following examples shows how to declare a ref class:
ref class Person { public: typedef Windows::Foundation::Collections::IMapView<Platform::String^, Platform::String^> NumbersView; Person(Platform::String^ name); void AddPhoneNumber(Platform::String^ type, Platform::String^ number); property NumbersView^ PhoneNumbers { NumbersView^ get(); } private: Platform::String^ name_; std::map<Platform::String^, Platform::String^> numbers_; };
Note the use of std::map in the private members and IMapView in the public interface. This shows the general idiom in which you use standard C++ types internally and Windows Runtime types at the ABI boundaries.
The following example shows how to implement a ref class:
Person::Person(Platform::String^ name): name_(name) { }
void Person::AddPhoneNumber(Platform::String^ type, Platform::String^ number)
{
numbers_[type] = number;
}
Person::NumbersView^ Person::PhoneNumbers::get()
{
return ref new Platform::MapView<Platform::String^, Platform::String^>(numbers_);
}
