【发布时间】:2015-10-09 08:24:36
【问题描述】:
所以我昨天才开始真正地学习 C++,并且由于之前的一些 Lua 经验,我很快就掌握了。我一直在 http://courses.caveofprogramming.com/ 上开设关于它的初学者课程。我试图创建一个类但遇到了一个错误。值得一提的是,专家使用 Eclipse 作为他的 EDI,而我使用 CodeBlocks。这就是我所拥有的。
main.cpp
#include <iostream>
#include "Cat.h"
using namespace std;
int main()
{
Cat tommy;
tommy.Grizzly() == true;
tommy.Bark();
return 0;
}
猫.cpp
#include "Cat.h"
#include <iostream>
using namespace std;
void Cat::Bark()
{
if (Grizzly())
{
cout << "RUFF!!!!!!" << endl;
}
else
{
cout << ":)" << endl;
}
}
猫.h
#ifndef CAT_H
#define CAT_H
class Cat
{
public :
bool Grizzly();
void Bark();
};
#endif // CAT_H
这是错误
C:\Users\Nas\Desktop\Coding Projects\Class Members 4\main.cpp|9|undefined reference to `Cat::Grizzly()'|
【问题讨论】:
-
像
tommy.Grizzly() == true;这样的比较在 Lua 中也没有多大作用。
标签: c++ eclipse class codeblocks undefined-reference