欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

objective-c中,分类的有关问题

更新时间: 2014-01-05 02:36:35 责任编辑: Author_N1

 

Objective-C中,分类的问题
最近在学习OC,遇到了一些问题,想问高手如何解决。


------------以下是Fraction.h文件内容------------------
#import <Foundation/Foundation.h>

@interface Fraction : NSObject
-(void) print;
-(double) convertToNum;
-(void) setTo: (int)n Over:(int)d;
-(void) reduce;
@property int numerator, denominator;
@end

------------以下是Fraction.m文件内容------------------
#import "Fraction.h"
@implementation Fraction
{
}
@synthesize numerator, denominator;
-(Fraction *)initWith:(int)n over:(int)d{
   //具体实现省略
}
-(void) reduce{
//具体实现省略
}
-(void) print{
//具体实现省略
}
-(double) convertToNum{
//具体实现省略
}
-(void) setTo:(int)n Over:(int)d{
//具体实现省略
}
@end

-------------以下是Fraction+Ops.h的内容-------------
#import "Fraction.h"

@interface Fraction (MathOps)
-(Fraction *)add:(Fraction *)f;
-(Fraction *)mul:(Fraction *)f;
-(Fraction *)sub:(Fraction *)f;
-(Fraction *)div:(Fraction *)f;
@end

----------以下是Fraction+Ops.m的内容-------------
#import "Fraction+MathOps.h"
#import "Fraction.m"

@implementation Fraction (MathOps)
-(Fraction *) add:(Fraction *)f{
//具体实现省略
}
-(Fraction *)sub:(Fraction *)f{
//具体实现省略
}
-(Fraction *)mul:(Fraction *)f{
//具体实现省略
}
-(Fraction *)div:(Fraction *)f{
//具体实现省略
}
@end


现在的问题是,已经确定实现的代码没有错误,但是编译的时候,提示编译失败。错误信息如下:
Ld /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Products/Debug/HelloWorld normal x86_64
    cd /Users/czclk/Desktop/HelloWorld/HelloWorld
    setenv MACOSX_DEPLOYMENT_TARGET 10.8
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Products/Debug -F/Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Products/Debug -filelist /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/HelloWorld.LinkFileList -mmacosx-version-min=10.8 -fobjc-arc -framework Foundation -o /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Products/Debug/HelloWorld

duplicate symbol _OBJC_IVAR_$_Fraction.numerator in:
    /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction.o
    /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction+MathOps.o
duplicate symbol _OBJC_IVAR_$_Fraction.denominator in:
    /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction.o
    /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction+MathOps.o
duplicate symbol _OBJC_CLASS_$_Fraction in:
    /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction.o
    /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction+MathOps.o
duplicate symbol _OBJC_METACLASS_$_Fraction in:
    /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction.o
    /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction+MathOps.o
ld: 4 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

请问高手如何解决,问题出在哪儿了呢?谢谢!!!!
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:36:35
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/12037/
本文WWW.DOC100.NET DOC100.NET版权所有。