dimanche 24 décembre 2017

How to define a Variadic template class's method in cpp file?

I am trying to create a variadic class A and place the definition of its constructor in the cpp file. I have tried A::A(Args.. args) , A<Args...>::A(Args.. args) and other options too but none of them worked.

How to define a variadic template class in cpp file in c++11?

// A.h

#include <tuple>

template<typename... Args>
struct A
{
    std::tuple<Args...> args_;

    A(Args... args);
};

//A.cpp

#include "A.h"


template<typename... Args>
A::A(Args.. args){
  args_ = std::make_tuple(args...);
}

// main.cpp

#include "A.cpp"

int main()
{
    A<int, int, int> a = A<int, int, int>(1, 2, 3);
}

Aucun commentaire:

Enregistrer un commentaire