实例化类模板的可变参数成员函数模板 [英] Instantiating a variadic member function template of a class template

查看:288
本文介绍了实例化类模板的可变参数成员函数模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在单独的 .cpp 文件中实例化类模板的可变参数成员函数模板?说,给定一个以上类的模板,在一组文件中: a.hpp ,定义了接口, a_impl.hpp 具有实现,具有实例化的 a.cpp -依次包含链中的每个先前对象,但类的用户(与开发人员相对)仅可见第一个)。

How can I instantiate a variadic member function template of a class template in separate .cpp file? Say, given an above class template in a set of files: a.hpp with definition of interface, a_impl.hpp with implementation and a.cpp with instantiation, - which includes each previous in the chain sequentially, but only the first is visible to the user of the class (as opposed to the developer).

对于参数包为空的情况特别感兴趣。

Especially interested in case of an empty parameter pack.

推荐答案

template <class A>
struct AA
{
  template<class Z, class... Q>
  void aa(double, Q... q) {};
};

template void AA<int>::aa<char>(double);
template void AA<int>::aa<char, char*>(double, char*);
template void AA<int>::aa<char, char*, char**>(double, char*, char**);

请注意,在您的设置中,只有开发人员可以实例化(需要按顺序查看实现)就能实例化。)

Note that in your setup only the "developer" can instantiate (one needs to see the implementation in order to be able to instantiate).

这篇关于实例化类模板的可变参数成员函数模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆