我正试图在窗口上学习目标c。 我的方案以警告汇编成册。
我的法典
#include <objc/Object.h>
@interface Greeter:Object
{
/* This is left empty on purpose:
** Normally instance variables would be declared here,
** but these are not used in our example.
*/
}
- (void)greet;
@end
#include <stdio.h>
@implementation Greeter
- (void)greet
{
printf("Hello, World!
");
}
@end
#include <stdlib.h>
int main(void)
{
id myGreeter;
myGreeter=[[Greeter alloc] init];
[myGreeter greet];
[myGreeter release];
return EXIT_SUCCESS;
}
我利用以下指挥机构汇编了我关于“全球疫苗”的方案。
gcc -o Greeter Greeter.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Libra
/Libraries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString
我收到以下关于汇编的警告:
: Greeter may not respond to +alloc [enabled by default]
: (Messages without a matching method signature [enabled by default]
: will be assumed to return id and accept [enabled by default]
: ... as arguments.) [enabled by default]
: no -init method found [enabled by default]
: no -release method found [enabled by default]
因此,当我听从我的可耻感时,这个物体不会被当即。
我正在使用来自MinGW的电梯,该电离层4.6.2。
------
当我从NSObject而不是目标延伸时,该方案会受到罚款。
页: 1
我的目标。
#include <objc/runtime.h>
@interface Object
{
Class isa;
}
@end
页: 1
我修改了我的法典如下。 这部法律汇编了罚款,但我不敢肯定这是否是处理事情的正确途径。
@interface Greeter
{
/* This is left empty on purpose:
** Normally instance variables would be declared here,
** but these are not used in our example.
*/
}
- (void)greet;
+ (id)alloc;
- (id)init;
- release;
@end
#include <stdio.h>
@implementation Greeter
- (void)greet
{
printf("Hello, World!
");
}
+ (id)alloc
{
printf("Object created");
return self;
}
- (id)init
{
printf("Object instantiated");
return self;
}
- release {}
@end
#include <stdlib.h>
int main(void)
{
id myGreeter;
myGreeter=[[Greeter alloc] init];
[myGreeter greet];
[myGreeter release];
return EXIT_SUCCESS;
}