mardi 21 juillet 2015

undefined reference to `Scrittura::creaScritta(char*, int)'

i have a warning and two errors with the following code:

  • warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
  • undefined reference to `Scrittura::creaScritta(char*, int)'
  • undefined reference to `Scrittura::scriviCentrato(Scrittura::Scritta)'

i use codeblocks 13.12

I hope someone can help to solve it.

// main
#include "Scrittura.h"
#include <iostream>

using namespace std;
using namespace Scrittura;

int main()
{
    scriviCentrato(creaScritta("Ciao mondo!", 12));
    scriviCentrato(creaScritta("Stiamo scrivendo centrato", 26));

    return 0;
}

//.h
#ifndef SCRITTURA_H
#define SCRITTURA_H


namespace Scrittura
{
    const int MAX_COLONNE=80;           // NUMERO MASSIMO COLONNE

    struct Scritta
    {
        char* testo;
        int lunghezza;
    };

    Scritta creaScritta(char*, int);    // INIZIALIZZA NUOVA SCRITTA
    void scriviCentrato(Scritta);       // CENTRA SCRITTA
};

#endif // SCRITTURA_H

//.cpp
#include "Scrittura.h"
#include<iostream>

namespace Scrittura
{
    Scritta creaScritta(char* testo, int lunghezza)
    {
        Scritta risultato;
        risultato.testo=testo;
        risultato.lunghezza=lunghezza;

        return risultato;
    }

    void scriviCentrato(Scritta scritta)
    {
        // AGGIUNGE GLI SPAZI NECESSARI PER LA CENTRATURA
        for(int i=0; i<(MAX_COLONNE - scritta.lunghezza - 1)/2; i++)
            cout << "";

        cout << scritta.testo;
    }

};

Aucun commentaire:

Enregistrer un commentaire