Visual C++ WinRT FAQ – Non-RT types in public signature

Your public WinRT classes cannot use non-RT types in their public signature. This is something people run into very frequently when they start writing WinRT components. For example, see the code below.

class Native { };

public ref class MyRef sealed
{
private:
        voidFoo1(Native n) { } // <--This is fine

public:
        voidFoo2(Native n) { } // <--This won't compile
};

You’ll get a compiler error there:

error C3986: 'Foo2': signature of member contains native type 'Native'

Note that this is by design. (If you think about it, it’s perfectly logical, since WinRT components can be consumed by any WinRT caller including non-C++ ones)

2 thoughts on “Visual C++ WinRT FAQ – Non-RT types in public signature”

  1. Hello
    thanks for this remark but how to instance this class from external class?
    MyRef ^ instance = ref new MyRef (Native variable); //not compile
    cannot access private member declared in class

Leave a Reply