object.c c++ mixed code and it support the stl
来源:互联网 发布:sql select 不等于 编辑:程序博客网 时间:2024/05/19 06:49
如题。不过不能给它obj-c用template。
objeTest.h
#import <Foundation/Foundation.h>
template<class T>
class Base
{
public:
T data;
public:
Base(T val=T())
{
data =val;
}
~Base(){}
void SetValue( T val)
{
data =val;
}
const T GetValue()const
{
return data;
}
};
//the template function determine whether the two object are equal.
template<class T>
bool IsCompare(const T *rval, const T *lval)
{
return [rval isC: lval];
}
@interface ObjTest : NSObject {
Base<int> * basedata;
}
- (id)initWithValue:(int) val;
- (void)delloc;
-(void)data:(int)val;
-(int)getdata;
-(NSString*)description;
//for the future,the template invoke it.
-(BOOL) isC:(ObjTest*)lval;
@end
objTest.mm(note this post file name)
#import "ObjTest.h"
#import "Engine.h"
@implementation ObjTest
- (id)initWithValue:(int) val
{
self = [super init];
if (self)
{
basedata = new Base<int>(val);
}
return self;
}
- (void)delloc
{
delete basedata;
//[super delloc];
}
-(void)data:(int)val
{
basedata->SetValue(val);
}
-(int)getdata
{
return basedata->GetValue();
}
-(NSString*)description
{
// NSString *formatstr = [[NSString alloc] initWithFormat:@"value is now:%i",(basedata->GetValue()) ];
// return [formatstr autorelease];
return [NSString stringWithFormat:@"value is now:%i",(basedata->GetValue()) ];
}
- (BOOL) isC:(ObjTest*) lval
{
BOOL breturn = NO;
if ([self getdata] == [lval getdata]) {
breturn =YES;
}
return breturn;
}
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// insert code here...
// NSMutableArray *array =
//
// [NSMutableArray arrayWithObjects:@"Miguel", @"Ben", @"Adam", @"Melissa", nil];
//
//
//
// NSPredicate *bPredicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] 'a'"];
//
// NSArray *beginWithB = [array filteredArrayUsingPredicate:bPredicate];
//
//compare the objects using the template function.
id obj = [[ObjTest alloc] initWithValue:101 ];
NSLog(@"value is %@",obj);
id obj2 = [[ObjTest alloc] initWithValue:101 ];
NSLog(@"value is %@",obj2);
bool bresult = IsCompare<ObjTest>(obj,obj2);
[obj release];
[obj2 release];
[pool drain];
return 0;
}
- object.c c++ mixed code and it support the stl
- C Error: mixed declaration and codes.
- Object-C中的#和##操作符(The # and ##Operator)
- ISO C90 forbids mixed declarations and code
- ISO C89 forbids mixed declarations and code
- ISO C89 forbids mixed declarations and code
- ISO C90 forbids mixed declarations and code
- [object-c] self and super
- Object-C Property and Synthesize
- Object-C NSArray and NSMutableArray
- Optimizing C and C++ Code
- Optimizing C and C++ Code
- C and C++ support in Emacs
- c plus STL and vector
- Writing-Efficient-C-and-C-Code-Optimization
- pf_ring userland code C code and C++ code Cross compile
- ISO C90 forbids mixed declarations and code 警告
- ISO C90 forbids mixed declarations and code 警告
- 各进制基数、符号及示例
- Android中activity A 启动 activity B时的细节问题
- android 9 patch 图片(.9.png 格式图片) 的特点和制作_oisoft 机器人图片
- 各进制基数、符号及示例
- 并查集 & 路径压缩
- object.c c++ mixed code and it support the stl
- ThreadLocal个人理解
- java.lang.NullPointerException异常,没有输出stackTrace的信息
- CountDownLatch的使用方法
- Android 平台搭建和Hello World
- 虚拟机中ubuntu挂载nfs成功,并为arm11烧录YAFFS2文件系统
- 发挥优势,无论什么优势;控制弱点,无论什么弱点
- 如何取得IP用户名等信息
- Linux信号量 sem_t简介