我有两个文件:
hello.h 和 hello.cpp
你好.h
#ifndef __HELLO_H__
#define __HELLO_H__
using namespace std;
void PrintMessage();
#endif
你好.cpp
#include <iostream>
#include "hello.h"
using namespace std;
void PrintMessage()
{
cout << "I want to be displayed!";
}
现在,我想PrintMessage()
在新的 .cpp 文件中使用,但我不断收到错误消息。这就是我正在做的事情:
打印信息.cpp
#include <iostream>
#include "hello.h"
using namespace std;
int main()
{
PrintMessage();
return 0;
}
我只是在做一些公然错误的事情吗?我确实将它们全部放在同一个文件夹中;我认为它与 Dev-C++(我用来编写/编译/运行的东西)有关,但我无法弄清楚。有人有想法么?
我在桌面上创建了一个文件夹,将所有三个文件都放入其中,然后我尝试printingmessage.cpp
完全按原样编译我的文件。这是我得到的错误:
[Linker error] Undefined reference to 'PrintMessage()'