我正在构建一个简单的 ActionTracker 程序。我有一个非常简单的 XAML 文件:
//XAML文件
<Page
x:Class="ActionTracker_V3.ActionDetails"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ActionTracker_V3"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<TextBox Text="{x:Bind temp, Mode=OneWay}"></TextBox>
</Grid>
</Page>
支持运行时类定义为:
//IDL文件
namespace ActionTracker_V3
{
runtimeclass ActionDetails : Windows.UI.Xaml.Controls.Page
{
ActionDetails();
String temp;
}
}
关联的*.h文件和*.cpp文件如下所示:
#include "ActionDetails.g.h"
namespace winrt::ActionTracker_V3::implementation
{
struct ActionDetails : ActionDetailsT<ActionDetails>
{
ActionDetails();
hstring temp();
void temp(hstring const& value);
};
}
namespace winrt::ActionTracker_V3::factory_implementation
{
struct ActionDetails : ActionDetailsT<ActionDetails, implementation::ActionDetails>
{};
}
*.cpp 文件是:
#include "pch.h"
#include "ActionDetails.h"
namespace winrt::ActionTracker_V3::implementation
{
ActionDetails::ActionDetails()
{
InitializeComponent();
}
hstring ActionDetails::temp()
{
throw hresult_not_implemented();
}
void ActionDetails::temp(hstring const& value)
{
throw hresult_not_implemented();
}
}
但是,当我编译这些文件时,出现以下错误:
Error C2039 'ActionDetails': is not a member of 'winrt::ActionTracker_V3::implementation' ActionTracker_V3 c:\users\kurian.kattukaren\source\repos\actiontracker_v3\actiontracker_v3\generated files\xamltypeinfo.g.cpp
我不知道是什么导致了错误。我在类声明中找不到任何错误。有人可以指出我哪里出错了吗?
最佳答案
根据列出的故障排除步骤here :
C++ 编译器产生错误“‘implements_type’:不是‘’的任何直接或间接基类的成员”。
当您使用实现类型的命名空间非限定名称(例如 MyRuntimeClass)调用 make 并且您没有包含该类型的 header 时,可能会发生这种情况。编译器将 MyRuntimeClass 解释为投影类型。解决方案是包含您的实现类型的 header (例如 MyRuntimeClass.h)。
我复制了上面的信息只是想说你的问题可能是由于编译器无法从你的项目中找到正确的头文件。但这并不意味着您的代码有任何问题。有可能是某些设置不正确,或者只是 Visual Studio 的问题。没有你的项目我也不能确定。如果这种情况总是发生在您的环境中并且您确定您的代码是正确的,请直接从 Visual Studio 报告它 -> 关于 -> 将反馈发送到开发者社区论坛。
无论如何,任何时候如果您的项目出现明显的错误,您都可以先尝试一个新项目作为测试。
关于c++ - 当 C++ winrt 页面类与 XAML 页面一起使用时,不是成员错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53402613/