const返回函数的值

时间:2010-11-28 17:06:41

标签: iphone objective-c const

我编写以下代码,但为什么编译器不显示警告或错误?

const computer* const activeComputer = [self.setting getActiveComputer];
activeComputer.name = [service name];
activeComputer.ipAddr = ipAddress;

getActiveComputer函数的声明

- (const computer* const) getActiveComputer

1 个答案:

答案 0 :(得分:4)

Objective-C中的点符号是调用对象getter / setter方法的简写。你拥有的东西相当于:

[activeComputer setName:[service name]];

我认为调用方法不会违反const声明,因此没有警告。

相关问题