• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
functions vs methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

functions vs methods


  • Subject: functions vs methods
  • From: Roland Silver <email@hidden>
  • Date: Thu, 5 May 2005 07:24:06 -0600

Given one of my classes, Foo, how can I define a function (not method) post() which accesses an instance variable textView of Foo? The following doesn't work:

//	Foo.h
#import <Cocoa/Cocoa.h>
#import <stdio.h>
@interface Foo : NSObject
{
    IBOutlet NSTextView *textView;
}
... method declarations ...

void post(const char *template, ...);
@end

//	Foo.m
@implementation Foo
... method definitions ...

void post(const char *template, ...) {
	va_list	args;
	char	*msg;
	NSString *nsMsg;
	va_start(args, template);
	vasprintf(&msg, template, args);
	va_end(args);
	nsMsg = [NSString stringWithCString:msg];
	[textView insertText:nsMsg]; //<------- error: 'textView' undeclared
} //end post
@end

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: functions vs methods
      • From: "Sean McBride" <email@hidden>
    • Re: functions vs methods
      • From: Nicko van Someren <email@hidden>
    • Re: functions vs methods
      • From: Ricky Sharp <email@hidden>
  • Prev by Date: Library for User Management
  • Next by Date: Re: functions vs methods
  • Previous by thread: Re: Library for User Management
  • Next by thread: Re: functions vs methods
  • Index(es):
    • Date
    • Thread