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.
精彩评论