Johnny Haddock
Johnny Haddock

Reputation: 475

How is a UWP interface property implement in C++/CX?

The correct syntax is eluding me and the docs don't have an example for this...

https://learn.microsoft.com/en-us/cpp/cppcx/properties-c-cx

This works in a header

public interface class IFoo
{
    property int Bar;
};

public ref class Foo sealed : public IFoo
{
public:
    property int Bar {
        virtual int get() { return _bar; }
        virtual void set(int bar) { _bar = bar; }
    };        
private:
    int _bar;
};

But if you want to implement the get and set in an implementation cpp file then I cannot figure out the syntax.

public interface class IFoo
{
    property int Bar;
};

public ref class Foo sealed : public IFoo
{
public:
    property int Bar {
        virtual int get(); // How are these implemented separately?
        virtual void set(int bar);
    };        
private:
    int _bar;
};

Upvotes: 2

Views: 359

Answers (1)

Vincent
Vincent

Reputation: 3746

The property get() and set() functions will have to be compiled as two separated functions in your cpp file:

int Foo::Bar::get()
{
    return _bar;
}

void Foo::Bar::set(int bar)
{
    _bar = bar;
}

Upvotes: 3

Related Questions