在c ++中,我按照youtube上的教程进行了操作,并且在我的头文件中遇到了一个问题。我有3个文件Main.cpp,Cat.cpp和Cat.h.在重复的帖子中,我似乎无法找到答案,而我所遵循的教程具有完全相同的代码。
Main.cpp的:
#include <iostream>
#include "Cat.h"
using namespace std;
int main(){
speak();
return 0;
}
Cat.cpp:
#include <iostream>
#include "Cat.h"
using namespace std;
void speak(){
cout << "miauw" << endl;
}
最终Cat.h:
#ifndef CAT_H_INCLUDED
#define CAT_H_INCLUDED
void speak();
#endif // CAT_H_INCLUDED
构建日志:
-------------- Build: Debug in test (compiler: GNU GCC Compiler)-----------
mingw32-g++.exe -Wall -g -c "C:\Users\73638G75MA\Documents\C++ projects\test\Main.cpp" -o obj\Debug\Main.o
mingw32-g++.exe -o bin\Debug\test.exe obj\Debug\Main.o
obj\Debug\Main.o: In function `main':
C:/Users/73638G75MA/Documents/C++ projects/test/Main.cpp:8: undefined reference to `speak()'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))