开发者

const return value of function

开发者 https://www.devze.com 2023-01-27 12:50 出处:网络
i write the following code, but why the compiler doesn\'t show warning or error? const computer* const activeComputer = [self.se开发者_如何学运维tting getActiveComputer];

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

精彩评论

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