在 C++ 中通过引用传递变量托管班!
我在 C++/cli 托管类中传递引用变量时遇到问题!很明显如何在非托管类中执行此操作,但我正在使用 c++/cli :/
这是我正在尝试执行的示例:
pManager->checkBoundary( int^ mX, int^ mY - 1 );
void Manager::checkBoundary( int^ cX, int^ cY )
{
if( cY >= 0 )
{
cY = this->mBoardHeight;
}
else if( cY < mBoardHeight )
{
cY = 0;
}
else if( cX >= 0 )
{
cX = this->mBoardWidth;
}
else if( cX < mBoardWidth )
{
cX = 0;
}
}
我知道这是不正确的,但我如何传递引用 var?
I'm having trouble passing a reference variable in a c++/cli managed class! Its obvious how to do it in an unmanaged class but i'm working with c++/cli :/
Here is an example of what i'm trying to do:
pManager->checkBoundary( int^ mX, int^ mY - 1 );
void Manager::checkBoundary( int^ cX, int^ cY )
{
if( cY >= 0 )
{
cY = this->mBoardHeight;
}
else if( cY < mBoardHeight )
{
cY = 0;
}
else if( cX >= 0 )
{
cX = this->mBoardWidth;
}
else if( cX < mBoardWidth )
{
cX = 0;
}
}
I know this is incorrect but how do i pass a reference var??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
C++/CLI 引用类似于
int% int_ref
。 :)A C++/CLI reference looks like this
int% int_ref
. :)使用与非托管类中相同的方法:void Manager::checkBoundary(int&cX, int&cY);
。如果这不起作用:如何分配传递的整数?
Use the same as you would in an unmanaged class:
void Manager::checkBoundary(int& cX, int& cY);
. If this does not work: how do you allocate the integers that you pass?