PDA

View Full Version : Converting from c++




MACnus
Dec 16, 2004, 06:46 AM
I'm currently converting a code from visual c to objc.

I have problems when using [] on method declarations

+ (id)Normal:(CVector *)vPolygon[];

this brings a parse error

waht do i have to do?

Thanks



jeremy.king
Dec 16, 2004, 09:13 AM
The [] characters are reserved for message sending (or method calls). Are you trying to define the input argument as an array?

iRobert
Dec 24, 2004, 08:44 AM
If you are [trying to define the input argument as an array], simply define the function like this:

+ (id)Normal:(CVector **)vPolygon;

you can then access it using (*vPolygon)[n];

see the following example: (it's ObjC version is trivial)


#include <iostream>

void printList(int ** list);

int main (int argc, char * const argv[]) {
int *myList = (int *)malloc(3*(sizeof(int)));

myList[0] = 12;
myList[1] = 14;
myList[2] = 16;

printList(&myList);

free(myList);

return 0;
}

void printList(int ** list) {
std::cout << (*list)[0] << std::endl;
std::cout << (*list)[1] << std::endl;
std::cout << (*list)[2] << std::endl;
}