开发者

Return type of an inline function

This method in Cocos2d:

/** Returns opposite of point.
 @return CGPoint
 @since v0.7.2
 */
stati开发者_运维知识库c inline CGPoint
ccpNeg(const CGPoint v)
{
    return ccp(-v.x, -v.y);
}

Why does it say 'CGPoint' after inline? Why not

static inline ccpNeg(...

?


Because the function wants to return a CGPoint.


static specifies the function's linkage and inline hints to the compiler that the function should be inlined. Neither of these is the function's return type, which every function must have (even if it's void). CGPoint is the function's return type.


CGPoint is the return type of the function.

If you just wrote static inline ccpNeg, the compiler wouldn't know what type of object the function returns (static and inline are just modifiers telling the compiler that it should inline the function; you still need a return type regardless).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜