AR2
AR2

Reputation: 11

Pass variables By Reference in C++ Managed Class!

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??

Upvotes: 0

Views: 3495

Answers (2)

Xeo
Xeo

Reputation: 131799

A C++/CLI reference looks like this int% int_ref. :)

Upvotes: 5

Oswald
Oswald

Reputation: 31657

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?

Upvotes: 1

Related Questions