vendredi 21 janvier 2022

Can you help me with oop?

This is my code:

Extractor.hpp
template <class O, class D> class Extractor{
  public:
    Extractor(
        std::vector<O>& input_data,
        Filtro<O>& filtro,
        Mapeador<O, D>& mapeador
    ): _input_data(input_data), _filtro(filtro), _mapeador(mapeador) {}

    unsigned int getData(std::vector<D>& output) {
      unsigned total = 0;
      for (O& data: _input_data) {
        if (_filtro.dadoValido(data)) {
          output.push_back(_mapeador.transformaDado(data));
          total++;
        }
      }
      return total;
    }

  private:

    std::vector<O>& _input_data;

    Filtro<O>& _filtro;

    Mapeador<O, D>& _mapeador;
};
Extractor.cpp
template <class NUM_TYPE>
class Num2Sqrt: public Mapeador<NUM_TYPE, NUM_TYPE> {
  NUM_TYPE transformaDado(NUM_TYPE& d) const override {
    // TODO: Implemente este metodo.
    d = d / d;
    return d;
  }
};

class FiltroNumPositivo: public Filtro<NUM_TYPE> {
  bool dadoValido(NUM_TYPE& d) const override {
    // TODO: Implemente este metodo.
    if (d > 0){
        return true;
    }else{
        return false;   
    }
  }
};

template <class NUM_TYPE> void test_filter_square_roots() {
    std::vector<unsigned> entrada;
    std::vector<Mapeador<std::string, int>> saida;

    read_input(entrada);  
    Filtro<int>* new_filtro;
    new_filtro = new FiltroNumPositivo<int>;

    Mapeador<int, int>* new_mapeador;
    new_mapeador = new Num2Sqrt<int>;

    Extractor<Filtro<int>,Mapeador<std::string, int>> new_extrator(new_filtro, new_mapeador, saida);

I just cut a little part of the code just to you all be capable to understand, but my problem is declaring the class of the template named Extractor, look at the extense error report(I cutted a little piece of the error):

ExtratorDeDados.cpp: In instantiation of ‘void test_filter_square_roots() [with NUM_TYPE = int]’: ExtratorDeDados.cpp:329:37: required from here ExtratorDeDados.cpp:243:61: error: no matching function for call to ‘ExtratorDeDados<Filtro, >Mapeadorstd::__cxx11::basic_string<char, int> >::ExtratorDeDados(Filtro&, Mapeador<int, >int>&, std::vector<Mapeadorstd::__cxx11::basic_string<char, int> >&)’ ExtratorDeDados<Filtro,Mapeador<std::string, int>> new_extrator(new_filtro, new_mapeador, >saida); ^~~~~~~~~~~~ In file included from ExtratorDeDados.cpp:3:0: ExtratorDeDados.hpp:124:5: note: candidate: ExtratorDeDados<O, D>::ExtratorDeDados(std::vector&, >Filtro&, Mapeador<O, D>&) [with O = Filtro; D = Mapeadorstd::__cxx11::basic_string<char, >int>] ExtratorDeDados( ^~~~~~~~~~~~~~~ ExtratorDeDados.hpp:124:5: note: no known conversion for argument 1 from ‘Filtro’ to >‘std::vector<Filtro, std::allocator<Filtro > >&’ ExtratorDeDados.hpp:113:35: note: candidate: constexpr ExtratorDeDados<Filtro, >Mapeadorstd::__cxx11::basic_string<char, int> >::ExtratorDeDados(const >ExtratorDeDados<Filtro, Mapeadorstd::__cxx11::basic_string<char, int> >&) template <class O, class D> class ExtratorDeDados { ^~~~~~~~~~~~~~~ ExtratorDeDados.hpp:113:35: note: candidate expects 1 argument, 3 provided ExtratorDeDados.hpp:113:35: note: candidate: constexpr ExtratorDeDados<Filtro, >Mapeadorstd::__cxx11::basic_string<char, int> >::ExtratorDeDados(ExtratorDeDados<Filtro, >Mapeadorstd::__cxx11::basic_string<char, int> >&&) ExtratorDeDados.hpp:113:35: note: candidate expects 1 argument, 3 provided ExtratorDeDados.cpp: In instantiation of ‘void test_filter_square_roots() [with NUM_TYPE = double]’: ExtratorDeDados.cpp:332:40: required from here ExtratorDeDados.cpp:243:61: error: no matching function for call to ‘ExtratorDeDados<Filtro, >Mapeadorstd::__cxx11::basic_string<char, int> >::ExtratorDeDados(Filtro&, Mapeador<int, >int>&, std::vector<Mapeadorstd::__cxx11::basic_string<char, int> >&)’ ExtratorDeDados<Filtro,Mapeador<std::string, int>> new_extrator(new_filtro, new_mapeador, >saida); ^~~~~~~~~~~~ In file included from ExtratorDeDados.cpp:3:0: ExtratorDeDados.hpp:124:5: note: candidate: ExtratorDeDados<O, D>::ExtratorDeDados(std::vector&, >Filtro&, Mapeador<O, D>&) [with O = Filtro; D = Mapeadorstd::__cxx11::basic_string<char, >int>] ExtratorDeDados( ^~~~~~~~~~~~~~~ ExtratorDeDados.hpp:124:5: note: no known conversion for argument 1 from ‘Filtro’ to >‘std::vector<Filtro, std::allocator<Filtro > >&’ ExtratorDeDados.hpp:113:35: note: candidate: constexpr ExtratorDeDados<Filtro, I would be really thankful if anyone can help me!

Aucun commentaire:

Enregistrer un commentaire