【问题标题】:How is a UWP interface property implement in C++/CX?UWP 接口属性如何在 C++/CX 中实现?
【发布时间】:2018-08-21 21:45:50
【问题描述】:

我不知道正确的语法,文档没有这个例子......

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

这适用于标题

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

但如果你想在实现 cpp 文件中实现 getset,那么我无法弄清楚语法。

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

【问题讨论】:

  • 只是 int Foo::Bar::get() { return _bar; }。不要忘记将它放在命名空间中。

标签: uwp c++-cx


【解决方案1】:

属性 get() 和 set() 函数必须在您的 cpp 文件中编译为两个单独的函数:

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

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

【讨论】:

    猜你喜欢
    • 2010-12-08
    • 2016-01-28
    • 2023-03-09
    • 1970-01-01
    • 2021-04-14
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多