C++: multiple definition...?

Hallo, ich habe in C++ einen Header erstellt, aber bei der Complierung kommt immer diese Fehlermeldung:

C:\Users\Admin\AppData\Local\Temp\ccdaLGOT.o:lexer.cpp:(.text+0x111): undefined reference to `Token::content[abi:cxx11]() const'
...(Zu lang zum abschicken)
collect2.exe: error: ld returned 1 exit status

Kann mir jemand sagen was der Fehler ist und wie ich ihn behebe?

token.hpp:

#ifndef TOKEN_HPP_
#define TOKEN_HPP_

#include <string>

class Token {
public:
    enum class Type {
        STRING,
        NUMBER,
        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

token.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 geht auch nicht
}

void Token::change_type(Type type) const noexcept {
    m_type = type;
}

Ich hoffe jemand kann mir dabei helfen!

LG

PC, Computer, Software, programmieren, compiler, Cplusplus, CPP, development, Informatik, Informatiker, Programmiersprache, C (Programmiersprache), Cpp Programierung
Programmiersprache Java: Wieso erhalte ich diese Fehlermeldung?

Hallo zusammen

Ich bin gerade wieder fleissig Java am programmieren und komme leider bei einem neuen Problem nicht weiter.

Der Code ist an und für sich schon fertig, nur schein bei der Zeile 17 (gem. Fehlermeldung etwas nicht korrekt zu sein, was ich leider nicht nachvollziehen kann. Kann mir jemand erklären wie das Problem behoben werden kann?

Von der Logik her müsste danach der Code funktionieren.

Aufgabenstellung:

2x Usereingabe -> 1x Min int Minimalwert & 1x Max int Maximalwert

Das Programm soll den ersten Index von int [] werte widergeben, welche das Minimum und Maximum Kriterium kumulativ erfüllt und danach sich beenden ohne weitere Werte anzugeben -> break.

int zähler habe ich als Indexcount verwendet.

Fehlermeldung:

Code an sich:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

int [] werte = {45, 34, 56, 63, 83, 18, 12, 79, 2, 35, 13, 68, 22, 54, 86, 33};

Scanner keyScan = new Scanner(System.in);

System.out.print("Minimum: ");

int min = keyScan.nextInt();

System.out.print("Maximum: ");

int max = keyScan.nextInt();

keyScan.close();

for (int zähler = 0; zähler<werte.length; zähler++) {

  if (werte [zähler] >= min && werte <= max) {

    System.out.print(werte[zähler]);

    break;}

 }

}

}
----------------------

Für eure Hilfe wäre ich sehr dankbar.

LG

Alex

Bild zum Beitrag
programmieren, Java, Programmiersprache, Fehlermeldung

Meistgelesene Beiträge zum Thema Programmiersprache