我的主要内容中有未定义的引用错误。不确定我做错了什么,并尝试更改名称和移动的东西,但不断得到相同的错误。我想知道它是不是我的IDE,但我真的不知道 这是代码:
#include <iostream>
#include "f.h"
#include "g.h"
using namespace std;
int main()
{
F f;
G g;
f.f();
g.g();
return 0;
}
下一个文件:
#ifndef F_H_INCLUDED
#define F_H_INCLUDED
class F
{
public:
void f();
};
#endif
下一个文件:
#ifndef G_H_INCLUDED
#define G_H_INCLUDED
class G
{
public:
void g();
};
#endif
下一个文件:
#include "f.h"
#include <iostream>
void F::f()
{
std::cout << "This was function f!" << std::endl;
}
下一个文件:
#include "g.h"
#include <iostream>
void G::g()
{
std::cout << "This was function g!" << std::endl;
}
编辑:所以我改变了来自&#34; f.h&#34;和&#34; g.h&#34;到&#34; f.cpp&#34;和&#34; g.cpp&#34;现在它有效......任何人都可以解释原因吗?
答案 0 :(得分:0)
它看起来很好,但要确保你的文件名是否正确,大小写之间有区别。
#include "f.h"
#include "g.h"
与
不一样#include "F.h"
#include "F.h"
答案 1 :(得分:0)
我用VS2013测试它是对的,如果你复制代码,请检查它。