"Warnung: Kann nicht finden, linker symbol für virtuelle Tabelle für Wert XXX Wert" mit GCC und GDB (CodeBlocks)

Ich bin immer ein runtime error ("Speicher kann nicht geschrieben werden"), dass, nach der Kontrolle durch den debugger, führt zu der Warnung in den Titel.

Header sind die folgenden:

componente.h:

#ifndef COMPONENTE_H
#define COMPONENTE_H

using namespace std;

class componente
{
        int num_piezas;
        int codigo;
        char* proovedor;
    public:
        componente();
        componente(int a, int b, const char* c);
        virtual ~componente();
        virtual void print();

};

#endif //COMPONENTE_H

ergänzen.h Umsetzung

#include "Componente.h"
#include <string.h>
#include <iostream>

componente::componente()
{
    num_piezas = 0;
    codigo = 0;
    strcpy(proovedor, "");
    //ctor
}

componente::componente(int a = 0, int b = 0, const char* c = "")
{
    num_piezas = a;
    codigo = b;
    strcpy(proovedor, "");
}

componente::~componente()
{
    delete proovedor;//dtor
}

void componente::print()
{
    cout << "Proovedor: " << proovedor << endl;
    cout << "Piezas:    " << num_piezas << endl;
    cout << "Codigo:    " << codigo << endl;
}

teclado.h

#ifndef TECLADO_H
#define TECLADO_H

#include "Componente.h"


class teclado : public componente
{
        int teclas;
    public:
        teclado();
        teclado(int a, int b, int c, char* d);
        virtual ~teclado();
        void print();


};

#endif //TECLADO_H

teclado.h Umsetzung

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

teclado::teclado() : componente()
{
    teclas = 0;//ctor
}

teclado::~teclado()
{
    teclas = 0;//dtor
}

teclado::teclado(int a = 0, int b = 0, int c = 0, char* d = "") : componente(a,b,d)
{
    teclas = c;
}

void teclado::print()
{
    cout << "Teclas: " << teclas << endl;
}

Die main-Methode, wo bekomme ich den runtime error ist der folgende:

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

using namespace std;

int main()
{
    componente a; //here I have the breakpoint where I check this warning
    a.print();
    return 0;
}

ABER, wenn statt der Schaffung einer "componente" Objekt, erstelle ich eine "teclado" - Objekt habe ich nicht die runtime-Fehler. Ich bekomme immer NOCH die Warnung beim Debuggen, aber das Programm verhält sich wie erwartet:

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

using namespace std;

int main()
{
    teclado a;
    a.print();
    return 0;
}

Zurück "Teclas = 0" plus die "Drücken Sie eine beliebige Taste..." - Sache.

Haben Sie eine Idee, warum der linker mit troube mit diesem? Es muss nicht zeigen, wenn ich rufen Sie das virtuelle Funktion, aber vor, während der Bauphase.

InformationsquelleAutor Heathcliff | 2012-01-01
Schreibe einen Kommentar