对不起,我的英语不太好。 我有这样的课程
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 从基本运行时类转换为派生类
答案 0 :(得分:1)
如果在C ++ / WinRT中编写运行时类,则将在不同的命名空间中获得多个具有相同名称的类。假设有一个名为NS1
的名称空间,其中有一个名为WrapPanel
的运行时类,您将得到winrt::NS1::WrapPanel
,winrt::NS1::implementation::WrapPanel
和winrt::NS1::factory_implementation::WrapPanel
。第一个是我们通常使用的运行时类的“投影”。第二个是“实现”,它实现运行时类;第三个是module.g.cpp
使用的“工厂”。
如果将基类转换为派生类,则应使用“投影”。看来您已经使用了“实现”。