Hallo, ich habe in C++ ein Programm geschrieben bei dem bei der complierung von dem Linker ein Fehler ausgegeben wird:
C:\Users\Admin\AppData\Local\Temp\ccbYu20m.o:lexer.cpp:(.text+0x111): undefined reference to `Token::content[abi:cxx11]() const'
<zu lang um es alles in die Frage zu schreiben>
C:\Users\Admin\AppData\Local\Temp\ccbYu20m.o:lexer.cpp:(.text+0x13b): undefined reference to `Token::type() const'
collect2.exe: error: ld returned 1 exit status
Ich weiß nicht was das Problem auslöst, ich hoffe jemand kann mir weiterhelfen:
Lexer.hpp:
#ifndef TOKEN_HPP_
#define TOKEN_HPP_
#include <string>
//Versuchen dieses Teil in C zu schreiben!
class Token {
public:
enum class Type {
STRING,
NUMBER, //Integer is every number in code that is not part of a identifier.
BOOLEAN,
IDENTIFIER,
EQUAL,
PLUS,
MINUS,
TIMES,
DIVIDE,
LESS_THAN,
GREATER_THAN,
COMMENT,
DOT,
COMMA,
SEMICOLON,
CURLY_BRACKET_RIGHT,
CURLY_BRACKET_LEFT,
APOSTROPHE,
COLON,
UNEXPECTED
};
Token (Type type) noexcept;
Type type () const noexcept;
bool is (Type type) const noexcept;
bool is_not (Type type) const noexcept;
std::string content () const noexcept;
void change_content (std::string content) const noexcept;
void add_to_content (std::string content) const noexcept;
void clear_content () const noexcept;
void change_type (Type type) const noexcept;
private:
Type m_type;
std::string m_content;
};
#endif
Lexer.cpp:
#include "token.hpp"
#include <string>
Token::Token(Type type) noexcept : m_type{type} {};
Token::Type Token::type() const noexcept {
return m_type;
}
bool Token::is(Type type) const noexcept {
return m_type == type;
}
bool Token::is_not(Type type) const noexcept {
return m_type != type;
}
std::string Token::content() const noexcept {
return m_content;
}
void Token::change_content(std::string content) const noexcept {
m_content = content;
}
void Token::add_to_content(std::string content) const noexcept {
m_content = m_content + content;
}
void Token::clear_content() const noexcept {
m_content.clear(); /*Die clear Funktion kann ich auch nicht aufrufen laut eclipse*/
}
void Token::change_type(Type type) const noexcept {
m_type = type;
}
Ich nutze G++ zum complieren und der Complierbefehl ist auch richtig, mein Betriebsystem ist Win10.
Danke im Voraus!
LG