Maison > Questions et réponses > le corps du texte
J'ai écrit deux cours aujourd'hui pendant le processus d'apprentissage, et
est apparu lors de la compilation.Créer tout pour l'outil Programe...
Compilation du fichier Programe.m...
Outil de liaison Programe ...
./obj/Programe.obj/Programe.m.o:(.data.rel 0x20) : référence non définie à '__objc_class_name_Tire'
./ obj/Programe.obj/Programe.m.o:(.data.rel 0x28) : référence non définie à '__objc_class_name_Engine'
collect2 : erreur : ld a renvoyé 1 état de sortie
make[3] : * [obj/Programe] Erreur 1
make[2] : * [internal-tool-all_ ] Erreur 2
make[1] : * [Programe.all.tool.variables] Erreur 2
make : * [internal-all] Erreur 2
Je ne sais pas comment résoudre cette erreur.
#import <Cocoa/Cocoa.h>
@interface Tire : NSObject
@end // Tire
#import "Tire.h"
@implementation Tire
-- (NSString *) description
{
return (@"I am a tire. I last a while");
} // description
@end // Tire
#import <Cocoa/Cocoa.h>
@interface Engine : NSObject
@end // Engine
#import "Engine.h"
@implementation Engine
-- (NSString *) description
{
return (@"I am an engine. Vrooom!");
} // description
@end // Engine
#import <Foundation/Foundation.h>
#import "Tire.h"
#import "Engine.h"
@interface AllWeatherRadial : Tire
@end // AllWeatherRadial
@implementation AllWeatherRadial
-- (NSString *) description
{
return (@"I an a tire for rain or shine");
} // description
@end // AllWeatherRadial
@interface Slant6 : Engine
@end // Slant6
@implementation Slant6
-- (NSString *) description
{
return (@"I an a slant-6. VROOOM!");
} // description
@end // Slant6
@interface Car : NSObject
{
Engine *engine;
Tire *tires[4];
}
-- (Engine *) engine;
-- (void) setEngine: (Engine *) newEngine;
-- (Tire *) tireAtIndex: (int) index;
-- (void) setTire: (Tire *) tire
atIndex: (int) index;
-- (void) print;
@end // Car
@implementation Car
-- (id) init
{
if ((self = [super init]))
{
engine = [Engine new];
tires[0] = [Tire new];
tires[1] = [Tire new];
tires[2] = [Tire new];
tires[3] = [Tire new];
}
return (self);
} // init
-- (Engine *) engine
{
return (engine);
}
-- (void) setEngine: (Engine *) newEngine
{
engine = newEngine;
}
-- (void) setTire: (Tire *) tire
atIndex: (int) index
{
if (index < 0 || index > 3) {
NSLog (@"bad index (%d) in setTire:atIndex:",index);
exit (1);
}
tires[index] = tire;
}
-- (Tire *) tireAtIndex: (int) index
{
if (index < 0 || index <3) {
NSLog (@"bad index (%d) in tireAtIndex:",index);
exit (1);
}
return (tires[index]);
}
-- (void) print
{
NSLog (@"%@", engine);
NSLog (@"%@", tires[0]);
NSLog (@"%@", tires[1]);
NSLog (@"%@", tires[2]);
NSLog (@"%@", tires[3]);
} // print
@end // Car
int main (int argc, const char * argv[])
{
Car *car = [Car new];
Engine *engine = [Slant6 new];
[car setEngine: engine];
int i;
for (i = 0; i < 4; i++){
Tire *tire = [AllWeatherRadial new];
[car setTire: tire
atIndex: i];
}
[car print];
getchar();
return (0);
} // main