mardi 5 mars 2019

The variable parameter template --compiled error

The code is compiled through and run well on vs2015, but can not be compiled and report error on gcc/g++ 7.4.0, as follows: gcc version 7.4.0 error

#include <iostream>
#include <memory>
class AA
{
public:
  template<typename R, typename... Args>
  R invoke(Args... args)
  {
   std::cout<< __FUNCTION__ << ":" << sizeof...(args) << std::endl;
   return R();
  }
  template<typename R, typename... Args>
  R call(Args... args)
  {
    return this->invoke<R, Args...>(args...);
  }
};
template<typename T>
class BB
{
public:
 BB(): lib(new T()){}
 std::shared_ptr<T> lib;
};
template<typename T, typename... Args>
BB<T> make_module(Args... args)
{
   BB<T> obj;
   obj.lib->call<T, Args...>(args...);
   return obj;
}
int main()
{
  BB<AA> obj = make_module<AA>(1, 2, 3);
  return 0;
}

Aucun commentaire:

Enregistrer un commentaire