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> {
...
}
};
class FiltroNumPositivo: public Filtro<NUM_TYPE> {
bool dadoValido(NUM_TYPE& d) const override {
...
}
};
template <class NUM_TYPE> void test_filter_square_roots() {
...
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!
Here's your declaration:
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) {}
Here's the call:
Extractor<Filtro<int>,Mapeador<std::string, int>> new_extrator(new_filtro, new_mapeador, saida);
So, O
is Filtro<int>
, and D
is Mapeador<std::string, int>
.
This means the parameters have to be:
std::vector<Filtro<int>>& input_data, Filtro<Filtro<int>>& filtro, Mapeador<Filtro<int>, Mapeador<std::string, int>>& mapeador
But, as std::vector<O>
you're passing new_filtro
which is Filtro<int>*
, and instead of Mapeador<O, D>
you're passing new_mapeador
which is Mapeador<int, int>*
.
So the parameters don't match to your declared types.