Out-of-line definition error on a class but it is declared in the header file
Fixed it.
I don't know why but Xcode did not save my changes on the header file. I closed Xcode and opened the header file and the changes aren't there. I added the methods again and saved. I opened the CPP file added the new method in it worked fine.
Really weird.
Comments
-
alxcyl about 3 years
Now this is a weird problem. I was coding two days ago and stopped and then continued just now. On my header file (
Fruit.h
) I added a method calledanimateGrow()
like so:Fruit.h:
class Fruit { private: // Member variables here public: // Other methods here void animateGrow( ); };
But when I try to add the same method in the CPP file, I get an
Out-of-line definition of 'animateGrow' does not match any declaration in 'Fruit'
error. It's declared in the header but Xcode does not seem to be able to find that method.Fruit.cpp:
#include "SimpleAudioEngine.h" #include "Fruit.h" #include "Tree.h" using namespace cocos2d; using namespace CocosDenshion; Fruit::Fruit( ) { // Constructor } // Getter Methods // Setter Methods // Other Methods void Fruit::animateGrow( ) { // I get an error here when I type it. }
Full Code: (links removed) (In the code, the
Tree
class exists and all other methods and functions are working fine except for theanimateGrow()
as it gives me the error) -
Admin about 11 yearsAfter being reopened Xcode appears to be OK in my case :)
-
Ofer over 8 yearsI had the exact same error message on BSD using clang. Your answer made me look at the header for my code, sure enough, I didn't declare the func in the header. Thanks!
-
hotpro over 8 yearsI wanna say it helps me.Thanks
-
μολὼν.λαβέ almost 8 yearsboom, bang! debugging someone's speghetti code and got this weird error, worked defined class in header, solved.