C++/CX is an extension of C++ language designed to use the Windows Runtime (WinRT) to build Windows Store applications, or reusable components for the different supported languages: JavaScript, NET (C#, VB.NET, etc.) and C++.
WinRT is a native API that uses a simplified version of the COM technology. This technology is based on interfaces, and does not support by default class inheritance, except for XAML classes. Therefore, this feature applies to C++/CX language in which we should favor the use of interfaces, except for some XAML use cases.
A C++/CX exposed class, that is intended to be used by a client application in one of the supported languages, must be declared sealed. This prevents its derivation by the client code.
// Vehicle.h
#pragma once
#include "pch.h"
namespace CxSandbox
{
public ref class Vehicle sealed
{
public:
Vehicle();
};
}The C++/CX class inheritance is possible provided that the C++/CX ancestors classes :
- are public (to be described in the metadata),
- inherit from a XAML class (typically Windows::UI::Xaml::DependencyObject),
- have non-public constructors (to prevent instanciation by client code).
Thus, we can create a Car class inherited from the Vehicle class as follows :
// Vehicle.h
#pragma once
#include "pch.h"
namespace CxSandbox
{
public ref class Vehicle : Windows::UI::Xaml::DependencyObject
{
internal:
Vehicle();
};
}
// Car.h
#pragma once
#include "pch.h"
#include "vehicle.h"
namespace CxSandbox
{
public ref class Car sealed : CxSandbox::Vehicle
{
public:
Car();
};
}








