[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to call?
From: |
stefan urbanek |
Subject: |
Re: How to call? |
Date: |
Wed, 5 Mar 2003 11:00:28 +0200 |
On Wed, 05 Mar 2003 08:29:02 +0000, Peter Karlsson wrote
> Ok, to give both the class and method the same name was not my
> purpose, I am still learning :-)
>
Who is not? :)
> The thing I wanted to do was just a function, like a function in C.
> How do I change my code to do that? I don't want to create an
> instance and all that.
Well, just create a function like you do in plain C, you do not need to
create a class (@interface and @impementation). Objective-C is a
superset/extension of C.
Stefan
>
> >From: Stefan Urbanek <urbanek@host.sk>
> >To: Peter Karlsson <vigour@hotmail.com>
> >CC: discuss-gnustep@gnu.org
> >Subject: Re: How to call?
> >Date: Wed, 05 Mar 2003 09:16:36 +0100
> >
> >On 2003-03-05 08:43:12 +0100 Peter Karlsson <vigour@hotmail.com> wrote:
> >
> >>Hi dear list!
> >>
> >>I have a problem. This is my interface file:
> >>
> >>@interface reset : NSObject
> >>{
> >>}
> >>- reset;
> >>@end
> >>
> >>This is my implementation file:
> >>
> >>@implementation reset
> >>- reset
> >>{
> >> printf("Hello Gnu People\n");
> >> return self;
> >>}
> >>@end
> >>
> >>The question is, how do I call reset? I tried just to type reset; and I
> >>got no errors or warnings when building but the reset code is not called,
> >>seems to be ignored. What am I doing wrong here?
> >>
> >
> >In your case, 'reset' is a name of a class and also a name of a method. To
> >call that method, you have to create an instance of that class and send it
> >the message 'reset'.
> >
> >main()
> >{
> > ...
> > reset myObject = [[reset alloc] init]; /* create an instance */
> >
> > [myObject reset]; /* send a message */
> > ....
> >}
> >
> >BTW. The naming convenience is that class names start with capital letter,
> >so it should be named Reset. But it is just a cosmetic thing.
> >
> >Stefan
> >
> >
>
> _________________________________________________________________
> Add photos to your e-mail with MSN 8. Get 2 months FREE*.
> http://join.msn.com/?page=features/featuredemail
- How to call?, Peter Karlsson, 2003/03/05
- Re: How to call?,
stefan urbanek <=