C++ C++;模板化类继承[无法转换模板]

C++ C++;模板化类继承[无法转换模板],c++,templates,C++,Templates,我有以下代码: #include <iostream> using namespace std; template<int k> struct Base{ int a = k; }; struct C1 : Base<1>{}; struct C2 : Base<2>{int b;}; typedef Base<1> C1T; template< typename BufferTyp

我有以下代码:

#include <iostream>
using namespace std;

template<int k>
struct Base{
   int a = k;
};

struct C1 : Base<1>{};
struct C2 : Base<2>{int b;};

typedef Base<1> C1T;


    template<
            typename BufferType,

            typename VerticesType,
            VerticesType BufferType::* VerticesField = nullptr
            >
    void t(){};


int main() {
// WHY this work??
    t<C1T , int, &C1T::a>();

// And this not?
// t<C1 , int, &C1::a>();

// ok.
//  t< Base<1>, int, &Base<1>::a >();

// also, ok
t<C2 , int, &C2::b>();
    return 0;
}
#包括
使用名称空间std;
样板
结构基{
int a=k;
};
结构C1:Base{};
结构C2:Base{int b;};
typedef-Base-C1T;
模板<
typename缓冲类型,
typename VerticesType,
VerticesType BufferType::*VerticesField=nullptr
>
void t(){};
int main(){
//为什么要这样做??
t();
//这不是吗?
//t();
//嗯。
//t();
//还有,好的
t();
返回0;
}

为什么我不能这样叫“t”

t<C1 , int, &C1::a>();
t();
但是,我得到了以下错误:

无法将模板参数“&Base::a”转换为“int C1::*”

另外,如果C1是类型定义的,我可以理解这种行为。

试试:

t<Base<1> , int, &C1::a>();
t();

Hmm。。。对于初学者来说,没有在成员指针上进行从基到派生的转换,所以它不会自动进行转换,但我发现您甚至不能强制转换它。@Mike-为什么它们必须是静态成员?这是指向members@uk4321的指针——“没有在成员指针上进行从基到派生的转换”——您在哪里了解这一点?“但我发现你甚至不能强制转换”-你是什么意思?@tower120 read和“你甚至不能强制转换”意味着我发现成员指针模板参数必须是
&X::Y
(根据GCC)格式,所以你不能在那里强制转换。@uk4321“我发现成员指针模板参数必须是&X::Y格式”-在我的示例中是哪种形式?@Kate说实话,错误消息中的格式是正确的。这和
t()是等效的。好的-我用typedef变量更新了我的问题。为什么它使用typedef而不使用继承?