对类的未定义引用::()C ++

时间:2015-08-08 06:09:40

标签: c++ constructor destructor

我只是学习构造函数和析构函数我正在按照这个人正在做的教程bucky tutorial。我觉得视频已经过时了?因为我按照他说的每一步,我仍然会收到错误。

的main.cpp

#include <iostream>
#include "TESTING.h"

using namespace std;

int main(){

    TESTING so;
    cout << "TEST" << endl;

}

TESTING.h

#ifndef TESTING_H
#define TESTING_H


class TESTING
{
    public:
        TESTING();
    protected:
        private:
};

#endif // TESTING_H

TESTING.cpp

#include "TESTING.h"
#include <iostream>
using namespace std;


TESTING::TESTING()
{
    cout << "TESTTTTT!!" << endl;
}

错误消息

\ main.o:main.cpp未定义对'TESTING :: TESTING()'的引用

构建日志

mingw32-g++.exe   -c D:\C++\TESTING!\main.cpp -o D:\C++\TESTING!\main.o
mingw32-g++.exe  -o D:\C++\TESTING!\main.exe D:\C++\TESTING!\main.o   
D:\C++\TESTING!\main.o:main.cpp:(.text+0x52): undefined reference to `TESTING::TESTING()'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
1 error(s), 0 warning(s) (0 minute(s), 1 second(s))

2 个答案:

答案 0 :(得分:1)

您只构建并链接 fi = di.GetFiles("*.jpeg").Where(file => file.CreationTimeUtc < DateTime.UtcNow.AddDays(-30)).ToArray(); 源文件,而不是main源文件。您还需要编译TESTING,然后与TESTING.cpp链接:

mingw32-g++.exe   -c D:\C++\TESTING!\TESTING.cpp -o D:\C++\TESTING!\TESTING.o
mingw32-g++.exe  -o D:\C++\TESTING!\main.exe D:\C++\TESTING!\main.o D:\C++\TESTING!\TESTING.o

答案 1 :(得分:1)

您需要在构建中包含两个编译单元。

这意味着需要编译两个源文件,以及链接命令中指定的相应目标文件。

目前,只有main.cpp被编译为一个对象,只有main.o被链接。

相关问题