调用具有模板参数作为参数的模板成员函数

时间:2018-10-25 16:07:48

标签: c++ templates

我有一段代码,编译器在其中泄漏了缺少的模板参数错误,但我不明白为什么。我在下面的代码中重现该问题。如果我不是使用模板参数V1实例化struct C,而是使用struct A,则问题将消失。有谁知道为什么会发生此错误?

#include <cstdio>
#include <iostream>

struct A
{
   void f(){ std::cout << "struct A" << std::endl; };
};

template<typename T1, typename T2, typename T3>
struct B
{
   void g(){ std::cout << "struct B" << std::endl; }
};

template<typename U1>
struct C
{      
   template< template< typename, typename, typename > class U2 >
   void h()
   {
       U2<int,int,int> u2;
       u2.g();
   }
};

template<typename V1>
struct D
{
   void i()
   {
     C<V1> c;  //if replace by C<A>, it compiles. 
     c.h<B>(); //error: missing template arguments before ‘>’ token                   
   }
};

int main()
{
   D<A> d;
   d.i();

   return 0;
}

0 个答案:

没有答案