C++ Cygwin 未定义对构造函数的引用

C++ Cygwin Undefined reference to constructor

在尝试构建我的小型测试时遇到一个错误,我不明白为什么它不起作用。我正在使用 Eclipse 和 Cygwin。 Header 和 Source 文件被分成不同的文件夹,我也把它们放在 Cygwin include 文件夹中。

控制台日志

16:05:41 **** Incremental Build of configuration Debug for project Testarea ****
make all 
Building target: Testarea.exe
Invoking: Cygwin C++ Linker
g++  -o "Testarea.exe"  ./Source/lint.o ./Source/tester.o   
./Source/tester.o: In function `main':
/cygdrive/d/CWork/Testarea/Debug/../Source/tester.cpp:4: undefined reference to `lint::lint()'
/cygdrive/d/CWork/Testarea/Debug/../Source/tester.cpp:4:(.text+0x20): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `lint::lint()'
collect2: error: ld returned 1 exit status
make: *** [makefile:47: Testarea.exe] Error 1

16:05:41 Build Finished (took 348ms)

tester.cpp

#include <iostream>
#include <lint.h>
int main(){
    lint* a = new lint();
    std::cout << "hallo";
    return 0;
}

lint.cpp

class lint{
    private:
        int* a;
    public:
        lint(){
            a = new int();
        };
        lint(int b){
            a = new int(b);
        };
        lint(lint& b){
            a = new int(b.value());
        };
        int value(){
            return *a;
        };
};

lint.h

#ifndef HEADER_LINT_H_
#define HEADER_LINT_H_
class lint{
    public:
        lint();
        lint(int b);
        lint(lint& b);
        int value();
};
#endif

你的问题是那里有 2 类。一个称为 lint,另一个称为 lint,但仅在 lint.cpp 文件中可用。

实施已完成:

#include "lint.h"
lint::lint() {}

等等。