cppwinrt Panel的子类(或其他类),需要哪些构造函数?

时间:2018-12-10 13:41:09

标签: c++-winrt

对不起,我的英语不太好。 我有这样的课程

   struct WrapPanel :winrt::Windows::UI::Xaml::Controls::PanelT<WrapPanel>
   {
   public:
       WrapPanel(std::nullptr_t) {};
       // other code.....
   }

在其他课程中使用

    WrapPanel wrapPanel{ ItemsPanelRoot().try_as<WrapPanel>()};
    //Error C2440   'initializing': cannot convert from 'initializer list' to 'WrapPanel'   

喜欢: https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/move-to-winrt-from-cx 从基本运行时类转换为派生类

1 个答案:

答案 0 :(得分:1)

如果在C ++ / WinRT中编写运行时类,则将在不同的命名空间中获得多个具有相同名称的类。假设有一个名为NS1的名称空间,其中有一个名为WrapPanel的运行时类,您将得到winrt::NS1::WrapPanelwinrt::NS1::implementation::WrapPanelwinrt::NS1::factory_implementation::WrapPanel。第一个是我们通常使用的运行时类的“投影”。第二个是“实现”,它实现运行时类;第三个是module.g.cpp使用的“工厂”。

如果将基类转换为派生类,则应使用“投影”。看来您已经使用了“实现”。