# fatal error: method definition not in @implementation context



## boyfarrell (Oct 26, 2005)

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


----------



## kainjow (Oct 26, 2005)

Make sure you have all #includes, all methods are in your .h, etc... can't do much else without code...


----------



## boyfarrell (Oct 26, 2005)

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.


----------



## kainjow (Oct 28, 2005)

Have you figured it out by now? If not, I'd be happy to download the project and check out the error myself...


----------



## boyfarrell (Oct 29, 2005)

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....


----------



## Mikuro (Oct 29, 2005)

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.


----------



## boyfarrell (Oct 30, 2005)

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.


----------



## kainjow (Oct 30, 2005)

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.


----------



## boyfarrell (Oct 31, 2005)

The @Class lets an class use the objects from another class but doesn't allow it to use any of that classes methods - is that right?

If so I don't think that will work. But I will give it a go!

Cheers, Kainjow.


----------



## kainjow (Oct 31, 2005)

You use @class in the .h, and the normal #includes in the .m. It's just the same, but better when you're using classes that use each other.


----------



## kainjow (Oct 31, 2005)

Just post your project or email it to me, I'll make it work


----------



## boyfarrell (Nov 1, 2005)

Rightyo! You've got it!

Dan.


----------

