UWP 接口 属性 如何在 C++/CX 中实现?
How is a UWP interface property implement in C++/CX?
我不知道正确的语法,文档中没有这方面的示例...
https://docs.microsoft.com/en-us/cpp/cppcx/properties-c-cx
这适用于 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;
};
但是如果你想在实现 cpp 文件中实现 get
和 set
那么我无法理解语法。
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;
};
属性 get() 和 set() 函数必须在您的 cpp 文件中编译为两个单独的函数:
int Foo::Bar::get()
{
return _bar;
}
void Foo::Bar::set(int bar)
{
_bar = bar;
}
我不知道正确的语法,文档中没有这方面的示例...
https://docs.microsoft.com/en-us/cpp/cppcx/properties-c-cx
这适用于 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;
};
但是如果你想在实现 cpp 文件中实现 get
和 set
那么我无法理解语法。
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;
};
属性 get() 和 set() 函数必须在您的 cpp 文件中编译为两个单独的函数:
int Foo::Bar::get()
{
return _bar;
}
void Foo::Bar::set(int bar)
{
_bar = bar;
}