c++uwpwinrt-xamluwp-xamlc++-winrt

Not a member error when C++ winrt Page Class used along with XAML page


I'm building a simple ActionTracker program. I have a very simple XAML file:

//XAML file

 <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>

The backing runtime class is defined as:

//IDL file

namespace ActionTracker_V3
{
runtimeclass ActionDetails : Windows.UI.Xaml.Controls.Page
{
    ActionDetails();
    String temp;
}
 }

The associated *.h file and *.cpp files are shown below:

#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>
{};
}

The *.cpp file is:

#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();
}
}

However, when I compile these files I get the following errors:

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        

I don't know what's causing the error. I could not find anything wrong in the class declaration. Could someone point out where I'm going wrong?


Solution

  • According to the troubleshooting steps listed on Troubleshooting C++/WinRT issues (slightly reformatted):

    The C++ compiler produces the error "'implements_type': is not a member of any direct or indirect base class of ''".

    This can happen when you call make with the namespace-unqualified name of your implementation type (MyRuntimeClass, for example), and you haven't included that type's header. The compiler interprets MyRuntimeClass as the projected type.

    The solution is to include the header for your implementation type (MyRuntimeClass.h, for example).

    I copied the above info just want to say that your problem may due to the compiler cannot find the right header from your project. But that does not mean your code has any problem. It is possible that some settings are not correct, or it is just Visual Studio's problem. Without your project I can also not be sure. If this always happen in your environment and you are sure your code is correct, please report it directly from Visual Studio->About->Send feedback to Developer Community forum.

    Anyway, any time if you have a strange error from your project, you can try a new project as a test first.