(1)WinRT对象和引用计数
- Platform::String^ str1 = "str1";
- Platform::String^ str2 = str1;
- Platform::String^ str3 = ref new Platform::String(L"str3");
(2)WinRT中的数字类型
- bool b = true;
- char c8 = 'A';
- char16 c16 = L'A'; // same as wchar_t
- int8 i8 = 0x12; // same as char
- int16 i16 = 0x1234; // same as short
- int32 i32 = 0x12345678; // same as int, long
- int64 i64 = 0x1234567890abcdef; // same as long long, __int64
- int8 ui8 = 0x12; // same as unsigned char
- int16 ui16 = 0x1234; // same as unsigned short
- int32 ui32 = 0x12345678; // same as unsigned int, unsigned long
- int64 ui64 = 0x1234567890abcdef; // same as unsigned long long, __uint64
- float32 f32 = 12.34E-23; // same as float
- float64 f64 = 1234.56E-234; // same as double, long double
说明:这些类型都定义在Platform命名空间中。
(3)ref class实现自定义类
用ref class标记一个自定义类,就可以使用winRT的对象的方式使用这个类了。当然,在类中,是可以混合使用标准C++的一些类型的。
(4)Value struct结构体
如果一个类只包含数据成员,那么就可以使用value struct定义
(5)WinRT中的property
在WinRT中,使用property关键字声明共有数据成员,而且,还可以为property设置访问它的时候get()、set()的逻辑。
Public ref class LangSample { //… // Backing store for propertyA. int _propertyAValue; // Property that has custom setter/getter property int PropertyA { int get() { return _propertyAValue; } void set(int propertyAValue) { if (propertyAValue != _propertyAValue) { _propertyAValue = propertyAValue; //fire event. (See event example below.) propertyChangedEvent(this, propertyAValue); } } } // Trivial get/set property that has a compiler-generated backing store. property Platform::String^ PropertyB; }(6)WinRT定义接口
WinRT也能实现类似于标准C++的接口功能,当然,标准C++本身并没有提供接口这一概念(很多新的语言如c#、java都有提供),但是标准C++使用纯虚类是可以实现这一功能的。WinRT使用interface关键字来定义一个类为接口类(只需要声明方法,而不需要实现的类),然后就可以被其它的ref class去继承和实现接口了。
(7)WinRT委托、事件、partial类等
WinRT还有一些其他的语法扩展,委托、事件等,发现这些扩展都跟C#一样了,所以不继续废话了。直接看参考链接吧。
PS:以为会有一些特别的地方,发现都是C#的旧东西了。
参考:
http://msdn.microsoft.com/en-us/library/windows/apps/hh454076(v=VS.110).aspx
http://blog.csdn.net/gengshenghong/article/details/7047795