使用Visual Studio 2019 16.10.2如何在C++/WinRT控制台程序中包含.NET组件?
IVector
的indexOf
方法需要来自System
的UInt32
结构。
System
在这种情况下是如何使用的?尝试使用命名空间会导致
"System' : a namespace with this name does not exist"
SO已经介绍了这一点,但仅适用于C++/CLI应用程序,而不适用于C++/WinRT控制台应用程序。该帖子中提供的解决方案也不起作用。
#include "pch.h"
#include <Windows.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
using winrt::Windows::Foundation::Collections::IVector;
using namespace System;
int main()
{
IVector<int> foo;
foo.Append(1);
UInt32 bar;
foo.indexOf(1, bar);
return EXIT_SUCCESS;
}
在这种情况下,pch.h
为空。
当您从文档右上角的语言下拉列表中选择合适的语言(C++/WinRT(时,您将看到C++/WinRT-特定签名:
bool IndexOf(T const& value, uint32_t & index);
您需要更换
UInt32 bar;
带有
uint32_t bar{};