|

楼主 |
发表于 2023-5-18 17:33:08
|
显示全部楼层
本帖最后由 两手空空儿 于 2023-5-18 17:36 编辑
写了一个简单的示例,3个文件在一个文件夹下,提示如下:
* 正在执行任务: C/C++: g++.exe 生成活动文件
正在启动生成...
D:\MinGW32\bin\g++.exe -fdiagnostics-color=always -g D:\mycpp\tt\main.cpp -o D:\mycpp\tt\main.exe
d:/mingw32/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\ADMINI~1\AppData\Local\Temp\ccRKel2h.o: in function `main':
D:/mycpp/tt/main.cpp:7: undefined reference to `a::a(int)'
d:/mingw32/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/mycpp/tt/main.cpp:9: undefined reference to `a::GetN()'
d:/mingw32/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/mycpp/tt/main.cpp:7: undefined reference to `a::~a()'
d:/mingw32/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/mycpp/tt/main.cpp:7: undefined reference to `a::~a()'
collect2.exe: error: ld returned 1 exit status
生成已完成,但出现错误。
* 终端进程已终止,退出代码: -1。
* 终端将被任务重用,按任意键关闭。
- #include <iostream>
- #include "a.h"
- using namespace std;
- int main(void){
- a op(123);
- cout << op.GetN() << endl;
- }
复制代码
- #include <iostream>
- using namespace std;
- class a{
- public:
- a(int n);
- ~a();
- int GetN();
- private:
- int m_num;
- };
复制代码
- #include "a.h"
- a::a(int n): m_num(n){
- }
- a::~a(){
- }
- int a::GetN(){
- return m_num;
- }
复制代码 |
|