Converting from c++

Discussion in 'Mac Programming' started by MACnus, Dec 16, 2004.

  1. macrumors newbie

    Joined:
    Dec 13, 2004
    #1
    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
     
  2. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #2
    The [] characters are reserved for message sending (or method calls). Are you trying to define the input argument as an array?
     
  3. macrumors newbie

    iRobert

    Joined:
    Mar 11, 2004
    Location:
    the Netherlands
    #3
    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)

    Code:
    #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;
    }
    
     

Share This Page