image
image

Go Back   macosx.com > Design, Media, Programming & Scripting > Software Programming & Web Scripting

Reply
 
LinkBack Thread Tools
  #1  
Old October 26th, 2005, 12:55 PM
Registered User
 
Join Date: Jun 2005
Location: London, UK.
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
boyfarrell is on a distinguished road
fatal error: method definition not in @implementation context

Hi everybody,

Compiler spits out two lines (i) saying " ChemicalPotential.m:1: error: parse error before 'ChemicalPotential' " (where ChemicalPotential is the name of my class). And (ii) ChemicalPotential.m:1: fatal error: method definition not in @implementation context .

I managed to solve the problem by changing the one of the methods arguments datatype to id. Any ideas why that fixed it?

I've not posted my code up because it's a very big class. Just wondering if any of the above sounds familiar?

Daniel
Reply With Quote
  #2  
Old October 26th, 2005, 06:20 PM
Registered User
 
Join Date: Nov 2000
Posts: 949
Thanks: 0
Thanked 0 Times in 0 Posts
kainjow is on a distinguished road
Make sure you have all #includes, all methods are in your .h, etc... can't do much else without code...
Reply With Quote
  #3  
Old October 26th, 2005, 08:13 PM
Registered User
 
Join Date: Jun 2005
Location: London, UK.
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
boyfarrell is on a distinguished road
Yeah, that's exactly what I thought the error was, but I checked through everything. I'll do it again with fresh eye tomorrow it will probably be obvious!

Cheers, Daniel.
Reply With Quote
  #4  
Old October 28th, 2005, 02:26 PM
Registered User
 
Join Date: Nov 2000
Posts: 949
Thanks: 0
Thanked 0 Times in 0 Posts
kainjow is on a distinguished road
Have you figured it out by now? If not, I'd be happy to download the project and check out the error myself...
Reply With Quote
  #5  
Old October 29th, 2005, 11:34 AM
Registered User
 
Join Date: Jun 2005
Location: London, UK.
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
boyfarrell is on a distinguished road
Hi Kainjow,

I finally got round to it today actually. Now if I post the stuff and it's a silly mistake I'm going to feel like a complete twonk. I'll post is shortly, there is something I just want to try first....
Reply With Quote
  #6  
Old October 29th, 2005, 12:29 PM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,722
Thanks: 7
Thanked 60 Times in 54 Posts
Mikuro will become famous soon enough
You say that changing something to 'id' fixed it, so my guess is that you were referring to a class that had not yet been loaded by the compiler. Are you sure you have all the necessary #includes in that .h file?

I've run into similar-sounding problems before when I had two classes that cross-referenced each other. Since they relied on each other, neither could be compiled until the other was compiled. I've still never found a really good way around that, so I just change my types to id (or whatever the closest parent class is), and typecast in my .m file when necessary.
__________________
Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.8
MacBook Pro — 2.26GHz C2D, 2GB RAM — OS 10.6.3

Useful programs: Privoxy, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc
Reply With Quote
  #7  
Old October 30th, 2005, 07:11 PM
Registered User
 
Join Date: Jun 2005
Location: London, UK.
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
boyfarrell is on a distinguished road
Hi everybody,

Yeah, I have just figured it out. I have two classes dependent on each other. That is to sat that each has methods that accepts objects of each others type. And as Mikuro said, the compiler can't load either till the other is loads.

So, Mikuro, I guess I'll leave them as id !

The only way round it would be to not use the 2nd class and add it's instance variables and methods into the 1st. However, the 1st class is already splitting at the seams - it's up to 80 methods!

Daniel.
Reply With Quote
  #8  
Old October 30th, 2005, 07:43 PM
Registered User
 
Join Date: Nov 2000
Posts: 949
Thanks: 0
Thanked 0 Times in 0 Posts
kainjow is on a distinguished road
No, it's not smart to leave classes as "id" if you can...

Are you putting all your #includes in the .h or the .m? What you should do, is put all your #includes in the .m except for the Cocoa one and the #include if your class inherits from something besides NSObject. For all other classes that you define in your methods or as class variables, use the @class declaration (or whatever it's called) to define these. The syntax goes like this:
@class MyClass1, MyClass2, ...;

Ever since I've used this method, I've never had problems with classes that require each other.
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting 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 Off
Pingbacks are Off
Refbacks are Off



All times are GMT -5. The time now is 01:11 AM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.5.1
Copyright 2000-2010 DigitalCrowd, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52