C++ 类的外定义错误,但它在头文件中声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11876459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Out-of-line definition error on a class but it is declared in the header file
提问by alxcyl
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 called animateGrow()
like so:
现在这是一个奇怪的问题。两天前我正在编码,然后停下来然后继续刚才。在我的头文件 ( Fruit.h
) 上,我添加了一个如下所示的方法animateGrow()
:
Fruit.h:
水果.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.
但是当我尝试在 CPP 文件中添加相同的方法时,出现Out-of-line definition of 'animateGrow' does not match any declaration in 'Fruit'
错误。它在标头中声明,但 Xcode 似乎无法找到该方法。
Fruit.cpp:
水果.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 the animateGrow()
as it gives me the error)
完整代码:(链接已删除)(在代码中,Tree
该类存在并且所有其他方法和函数都可以正常工作,除了animateGrow()
因为它给了我错误)
采纳答案by alxcyl
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.
我不知道为什么,但 Xcode 没有将我的更改保存在头文件中。我关闭了 Xcode 并打开了头文件,但更改不存在。我再次添加了方法并保存。我打开了 CPP 文件,在其中添加了新方法,效果很好。
Really weird.
真的很奇怪。