开发者

const return value of function

i write the following code, but why the compiler doesn't show warning or error?

const computer* const activeComputer = [self.se开发者_如何学运维tting getActiveComputer];
activeComputer.name = [service name];
activeComputer.ipAddr = ipAddress;

declaration of getActiveComputer function

- (const computer* const) getActiveComputer


Dot notation in objective-C is short-hand for calling an objects getter/setter methods. What you have would be equivalent to:

[activeComputer setName:[service name]];

I would think that calling a method would not violate the const declaration so there is no warning.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜