[英]C++/CX property throwing error on set
I have a class: 我有一节课:
ref class Coord
{
public:
property float X {
float get() { return X; }
void set( float value )
{
X = value; // THROWS EXCEPTION
}
};
property float Y {
float get() { return Y; }
void set( float value ) { Y = value; }
};
property float Z {
float get() { return Z; }
void set( float value ) { Z = value; }
};
};
I make a new copy of it: 我制作了一份新的副本:
Coord^ playerRotation = ref new Coord();
I try to set one of the properties' values: 我尝试设置其中一个属性的值:
playerRotation->X = 0.0f;
It runs to this part of my class code: 它运行到我的类代码的这一部分:
X = value; // THROWS EXCEPTION
and throws an exception: 并抛出异常:
Unhandled exception at 0x00115299 in Game.exe: 0xC00000FD: Stack overflow (parameters: 0x00000001, 0x008E2FD0).
What am I doing wrong with the C++/CX properties 我在C ++ / CX属性上做错了什么
I don't know much about C++/CX, but guessing from the error message 我对C ++ / CX了解不多,但是从错误消息中猜测
Stack overflow
堆栈溢出
doing X = value;
做
X = value;
is actually calling X::set()
which in turn does X = value;
实际上是调用
X::set()
,而X = value;
X::set()
X = value;
... you go into an infinite loop and thus causes a stack overflow. ...你进入一个无限循环,从而导致堆栈溢出。
Based on the documentation , you need to define a backing store variable for property X
. 根据文档 ,您需要为
property X
定义后备存储变量。
ref class Coord
{
float m_x; // Backing store for property X
public:
property float X {
float get() { return m_x; }
void set( float value )
{
m_x = value;
}
};
...
You might also want to do the same for property Y
and property Z
. 您可能还想对
property Y
和property Z
执行相同的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.