ssk
ssk

Reputation: 9265

Pass by reference in objective c

I am a calling c++ method from objective c:

C++ Method:

void TestMethod( size_t& outputSize,
                 OutputArray& outputArray );

Objective C:

-(void) testMethodObjc : outputSize,
       OutputArrayObjc : outputArray
{

     TestMethod( outputSize, [outputArray getArray ]);
}

How do I accomplish this? I hear from other postings that objective-c does not support pass by reference.

Upvotes: 0

Views: 297

Answers (2)

newacct
newacct

Reputation: 122518

Objective-C, like C, does not support pass by reference.

Like C, you can take the address of the variable and pass a pointer instead. And to manipulated the original variable in the function you would need to dereference the pointer.

Upvotes: 1

Undo
Undo

Reputation: 25697

You should be able to - Obj-C is a strict subset of C. Just make sure that the file the code is in is a .mm file - not just .m

Upvotes: 1

Related Questions