«Предупреждение: не удается найти символ компоновщика для виртуальной таблицы для значения XXX» с использованием GCC и GDB (CodeBlocks)

Я получаю сообщение об ошибке выполнения («память не может быть записана»), которая после проверки с помощью отладчика приводит к предупреждению в заголовке. .

Заголовки следующие:

component.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

Complement.h реализация

#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 реализация

#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;
}

Основной метод, при котором я получаю ошибку времени выполнения, - это следующее:

#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;
}

НО, если вместо создания объекта "component" я создаю объект "teclado", я не получаю ошибку времени выполнения. Я ВСЕ ЕЩЕ получаю предупреждение во время отладки, но программа ведет себя так, как ожидалось:

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

using namespace std;

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

Это возвращает «Teclas = 0» плюс «Нажмите любую клавишу ...».

Вы хоть понимаете, почему у компоновщика возникли проблемы с этим? Он не появляется, когда я вызываю виртуальную функцию, но раньше, во время построения.

7
задан BЈовић 2 January 2012 в 08:05
поделиться