vendredi 11 février 2022

template argument 1 is invalid [closed]

The following code won't compile and the error message is "template argument 1 is invalid" when calling the foo() method of "obj". I can´t figure out why and am here for help. Any hint is appreciated!

//main.cpp
#include "A.hpp"
#include <string.h>
#include <vector>
#include <memory>
#include <cstddef>
#include <tuple>

std::shared_ptr<A::H> obj = A::create_obj();
const size_t sz;
std::vector<std::tuple<int, A::b>> inputs(sz);
for(int i = 0; i < sz; i++){
   A::b b;
   float v[5] = {1.0,2.0,3.0,4.0,5.0};
   memcpy(b.points, v, sizeof(b.points));
   inputs[i] = make_tuple(i,b);
}

std::vector<int> results = obj->foo(inputs); // template argument 1 is invalid

//A.hpp
namespace A{
  using namespace std;
  struct b { float points[5];};
  
  typedef std::tuple<int,b> input;

  class H{
  public:
      virtual std::vector<int> foo(const std::vector<input>& inputs) = 0;
  };
  
  std::shared_ptr<H> cretae_obj();
} // namespace A

//X.hpp
template<typename Input>
class E{
public:
  Input input;
  virtual ~E(){}
  virtual std::vector<int> foo(const std::vector<Input>& inputs) {return vector<int>{1,2};}
}

//A.cpp
#include "A.hpp"
#include "X.hpp"


namespace A {
using Eimpl = E<input>;
class Himpl : public H, public Eimpl {
    virtual ~Eimpl() {}
    virtual std::vector<int> foo(const std::vector<input>& inputs) override { return Eimpl::foo(inputs);}
    shared_ptr<H> create_obj(){
        shared_ptr<Himpl> instance(new Himpl());
        return instance;
    }
};
} // namespace A

Aucun commentaire:

Enregistrer un commentaire