C++ - `Lexer::Tokenize 的函数多重定义

C++ - function multiple definition of `Lexer::Tokenize

所以我在尝试编译一个文件时遇到了这个错误(mingw-64):

C:\Users\me\AppData\Local\Temp\ccfdOWKk.o:EKLexer.cpp:(.text+0x0): multiple definition of `Lexer::Tokenize(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
C:\Users\me\AppData\Local\Temp\cc9yNSun.o:EnderKnightShell.cpp:(.text+0x0): first defined here
C:\Users\me\AppData\Local\Temp\ccfdOWKk.o:EKLexer.cpp:(.text+0x36a): multiple definition of `Lexer::ProcessVariables(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
C:\Users\me\AppData\Local\Temp\cc9yNSun.o:EnderKnightShell.cpp:(.text+0x36a): first defined here
collect2.exe: error: ld returned 1 exit status

我试过查找,但 none 似乎符合我遇到的问题(似乎涉及正在使用的功能)。我不太喜欢 C++,所以我不确定到底发生了什么

EnderKnightShell.cpp

#include <iostream>
#include <fstream>
#include <string>
#include "EKLexer.cpp"
#include <C:\EndorCore\EnderKnight Python Port\Full Language\C++ Compiler\Headers\PythonStatements.h>
using std::string;
using std::ifstream;
using std::vector;
using py::Python;

ifstream EnderScript("Test.ek");

int main() {
    Lexer EkLexer;
    Python python;
    cout << "EnderKnight C++ Port Beta 1:" << endl;
    for(string CodeLine; getline(EnderScript, CodeLine);){
        EkLexer.Tokenize(CodeLine);
    }
    for (int i = 0; i < python.splitlines.size(); i++){
        for (int j = 0; j < python.splitlines[i].size(); j++){
            cout << python.splitlines[i][j] << endl;
        }
    }
}

EKLexer.cpp

class Lexer{
    private:
        typedef vector<map<string, string>> Tokens;
        typedef vector<string> KeyWords;

        Tokens tokens;
        KeyWords keywords{
            "echo",
            "goto",
            "stop",
            "math",
            "var",
            "edef",
            "end_edef",
            "/*",
            "if",
            "end_if_state"};
    public:
        void Tokenize(string);
        void ProcessVariables(string);
        Python python;
};


void Lexer::Tokenize(string Code){
    stringstream s(Code);
    string temp;

    while (s >> temp) {
        if (temp.compare("echo") == 0) {
                map<string, string> EchoMap {{"echo", Code}};
                tokens.push_back(EchoMap);
        }
        else if (temp.compare("var") == 0) {
                Lexer::ProcessVariables(Code);
        }

        // more code

void Lexer::ProcessVariables(string Code){
        python.Split(Code, '=');
}

感谢 templatetypedef 的评论,我发现问题是包含一个 .cpp 文件。解决方案是使用头文件和 cpp 源文件组合