如何制作像 CGRectMake (iphone) 这样的结构生成器
我有一个带有两个 CGFloat 的 struct HLRange,
struct HOLRange
{
CGFloat min;
CGFloat max;
};
typedef struct HOLRange HOLRange;
但是如何制作像 HLRangeMake(1,2); 这样的函数? ..像CGRectMake?
--编辑--
我的头文件
#import <Foundation/Foundation.h>
struct HOLRange
{
CGFloat min;
CGFloat max;
};
typedef struct HOLRange HOLRange;
HOLRange HOLRangeMake(CGFloat min, CGFloat max) {
HOLRange range;
range.min = min;
range.max = max;
return range;
}
@interface Structs : NSObject {
}
@end
error message: ld: duplicate symbol _HOLRangeMake in /Users/Documents/projects/iphone/test/catalog/base1/build/base1.build/Debug-iphoneos/base1.build/Objects-normal/armv6/base1AppDelegate.o and /Users/Documents/projects/iphone/test/catalog/base1/build/base1.build/Debug-iphoneos/base1.build/Objects-normal/armv6/main.o
i have a struct HLRange with two CGFloat's
struct HOLRange
{
CGFloat min;
CGFloat max;
};
typedef struct HOLRange HOLRange;
but how do i make a function like HLRangeMake(1,2); .. like CGRectMake?
--EDIT--
my header file
#import <Foundation/Foundation.h>
struct HOLRange
{
CGFloat min;
CGFloat max;
};
typedef struct HOLRange HOLRange;
HOLRange HOLRangeMake(CGFloat min, CGFloat max) {
HOLRange range;
range.min = min;
range.max = max;
return range;
}
@interface Structs : NSObject {
}
@end
error message: ld: duplicate symbol _HOLRangeMake in /Users/Documents/projects/iphone/test/catalog/base1/build/base1.build/Debug-iphoneos/base1.build/Objects-normal/armv6/base1AppDelegate.o and /Users/Documents/projects/iphone/test/catalog/base1/build/base1.build/Debug-iphoneos/base1.build/Objects-normal/armv6/main.o
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在 CGGeometry.h 中查看 CGRectMake 源代码,以便您可以执行相同的操作:
编辑: 您必须将函数定义为内联函数或将其实现移至 .m 文件。当您的函数在导入 HoleRange.h (?) 标头的每个编译单元中定义时,您会收到链接器错误。
You can see CGRectMake source in CGGeometry.h so you can do the same:
Edit: You must either define your function as inline or move its implementation to .m file. You're getting linker errors as you function becomes defined in every compile unit that imports HoleRange.h (?) header.
旧帖子。不过,我想为未来的观众分享我解决这个问题的方法。
您可以像这样定义您的 Stuct 和 Make 函数。又短又快。
Old post. However, I'd like to share my method of resolving this problem for future viewers.
You can define your stuct and Make function like this. Short and quick.
我更喜欢这个格式。它在视觉上更有意义并且看起来更“正确”。
I like the format of this better. It makes more sense visually and seems more "correct."