objective c - Pass a struct to a class method -


i wanted able this:

vec2 pos(1,5); myactor.position = [coord positionfrom: pos ]; 

using structure:

typedef float32 float; struct vec2 {     vec2(float32 xx, float32 yy) {         x = xx;         y = yy;     }     float32 x, y; }; 

coord.h

@interface coord : nsobject { } +(cgpoint) positionfrom: (vec2) pos; +(cgpoint) positionfromangle: (float32) angle; 

coord.mm

#import "coord.h" @implementation coord +(cgpoint) positionfrom:(vec2) pos {     return cgpointmake( pos.x * 32, pos.y * 32); } +(cgpoint) positionfromangle:(float32) angle {     return cgpointmake( cos(angle) * 32, cos(angle) * 32); } @end 

but these errors (in coord.h, on positionfrom lines):

expected ')' before 'vec2' expected ')' before 'float32' 

this should be:

+(cgpoint) positionfrom: (struct vec2) pos; 

or else have failed import header file defines vec2.

you have trailing ] in return statement of positionfrom:.

btw, stylistically, kind of thing done function rather class method. this:

cgpoint cgpointfromvec2( struct vec2 pos ); 

that makes parallel cgpointfromstring().


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -