Error compiling a class in C ++

2

I get two mistakes and I do not know why.

Statement of the exercise:

  

Implement the TAD (abstract data type) ConjuntoCadenas .

     

This TAD will consist of a structure capable of storing a set of at most 100 different strings.

     

The TAD will be implemented by a class called ConjuntoCadenas in a module named ccadenas ( ccadenas.h and ccadenas.cpp ).

     

The namespace used in this module must be modulosp2 .

     

The operations that will have this TAD defined are:

     
  • leerDeFichero : You will receive as a parameter the name of a file with one string per line. The method will add the strings that appear in the file to the set.

  •   
  • escribirAFichero : You will receive as a parameter the name of a file and what   will overwrite with the strings that the set contains.

  •   
  • incluir : Receives a string as a parameter and adds it to the set. If the string already exists in the set it will not do anything.

  •   
  • pertenece : It receives as a parameter a string and returns if it belongs or not to the set.

  •   
  • eliminar : It receives as a parameter a string and if it belongs to the set it eliminates it.

  •   
  • listar : Shows all the strings of the set per screen.

  •   
  • vaciar : Remove all elements from the set.

  •   

I just made the first point to see how it started.

This is the code ccadenas.h :

#ifndef CCADENAS_H
#define CCADENAS_H

#include <iostream>
#include <fstream>
#include <string>

namespace modulosp2 {
    class ConjuntoCadenas {
        public:
        void leerDeFichero(std::string fichero);

        private:
        static const int MAX=100;
        typedef std::string TDatos[MAX];
        struct conjunto {
            int tamanyo=0;
            TDatos cadena;
        };
        conjunto datos;
        std::string linea;  
    };
}
#endif // CCADENAS_H

The code ccadenas.cpp :

#include "ccadenas.h"
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

namespace modulosp2 {
    void ConjuntoCadenas::leerDeFichero(string fichero) {
        ifstream fin;

        fin.open(fichero.c_str());

        while (!fin.eof()) {
            if(datos.tamanyo<MAX) {
                lleno=false;
                getline(fin, linea);
                datos.cadena[datos.tamanyo]=linea;
                datos.tamanyo++;
            } else {
                lleno=true;
            }
        }
        fin.close();
    }
}

Which I get the following errors:

  

undefined reference to WinMain @ 16

     

error: ld returned 1 exit status

Finally the main code conjuntos.cpp :

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

using namespace modulosp2;
using namespace std;

int menu() {
    int op;
    cout<<"\t0. Fin"<<endl;
    cout<<"\t1. Leer de fichero"<<endl;
    while(op<0||op>1) {
        cout<<"\tOpcion?: "<<endl;
        cin>>op;
    }
    return op;
}

int main() {
    int op;
    string fichero;
    ConjuntoCadenas concad;
    do {
        op=menu();
        switch(op) {
            case 1:
                cout<<"\tIntroduzca el nombre del fichero"<<endl;
                getline(cin, fichero);
                concad.leerDeFichero(fichero);
            break;
        }
    }while(op!=0);
    return 0;
}

Which I get the following errors:

  

modulosp2 :: SetChains :: readFile (std :: string)

     

error: ld returned 1 exit status

    
asked by J-- 18.03.2017 в 20:10
source

1 answer

0

It seems that you have to create a project and include all the files to build the application. In the first case, when compiling strings.cpp, what you are saying is that you can not find the main () function of the project. In the second, when you compile sets.cpp, you are saying that you do not know anything about the ClassCadenas class.

    
answered by 18.03.2017 / 21:34
source