Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Can you call a class method without creating an instance?

Can you call a class method without creating an instance?
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Mar 18, 2002, 11:13 PM
 
Do I have to create an instance before I can call a class method in Cocoa? I imported the class and am trying to call a method from it but I keep getting a "'query' undeclared (first use in this function)" error. query is the name of the class.

thanks,
kman
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Mar 19, 2002, 12:20 AM
 
Nope. There are lots of cases where you call class methods without having instances around (usually to get instances, like <font face = "courier">[NSWorkspace sharedWorkspace]</font> or <font face = "courier">[NSString stringWithContentsOfFile:]</font>).

You're probably running into a different problem. My guesses:
  • Has the class been properly declared in whatever header file you're importing?
  • Class names are case sensitive, and generally begin with an uppercase letter. Are you referring to the class by the correct name?
  • Is the class from a framework or library, in which case you need to make sure said framwork/library is properly linked into your project?
Rick Roe
icons.cx | weblog
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Mar 19, 2002, 10:17 AM
 
Thanks, Rick. I worked my way through the problem. As you suggested I had an error in the class declaration that was a bit difficult to find. Once I located and fixed it, everything is working fine.

kman
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:22 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2