objective-c构造函数举例
来源:互联网 发布:阿里云流量计费标准 编辑:程序博客网 时间:2024/04/30 09:21
#include <Foundation/Foundation.h>
#include <stdio.h>
@interface Container:NSObject
{
int number;
}
-(void) setNumber:(int) n;
-(int) intValue;
-(Container*) init:(int)n;
@end;
@implementation Container
-(void) setNumber:(int) n
{
number=n;
}
-(int) intValue
{
return number;
}
//构造函数
-(Container*)init:(int) n
{
self=[super init];
if (self){
[self setNumber:n];
}
return self;
}
@end
int main(void)
{
Container *object=[[Container new] init : 3];
printf( "The number is %i\n", [object intValue]);
return 0;
}
输出结果:
The number is 3
0 0
- objective-c构造函数举例
- objective-c 构造函数
- Objective-c构造函数
- objective-c之构造函数
- Objective-C入门05:自定义构造函数
- objective-c的构造函数测试
- 2.c++与objective-c中的构造方法(构造函数)
- objective-c 类使用举例!
- Objective-C - 构造方法
- 【Objective-C】构造方法
- Objective-C构造方法
- Objective-C 构造方法
- objective-c中的构造函数(对象初始化)(七)
- objective-c中的构造函数(对象初始化)(七)
- Objective-C学习- 便利初始化函数和便利构造器
- Objective-C中的便利初始化函数和便利构造器
- objective-c中的构造函数(对象初始化)(七)
- 构造函数与析构函数举例
- C语言原始数据类型
- XCode
- 初学者:介绍NSLog的使用
- 函数指针
- objective-c 类使用举例!
- objective-c构造函数举例
- objective-c 中isMemberOfClass的使用举例isKindOfClass的应用举例
- respondsToSelector instancesRespondToSelector
- 魅族Ubuntu phone系统手机曝光
- C++中ctype函数库
- C++ <vector>入门(1)
- C++ <vector>入门(2)
- 张瑞敏再发狠话:未来硬件不要钱,软件要钱
- c++ algorithm 的用法