C++ boost::remove_指针是如何工作的?
因此,remove\u引用或remove\u指针始终返回原语类型 我知道他们在模板元编程中使用所谓的模板专门化来实现这一点,但我不太明白如何实现 例如下面的例子C++ boost::remove_指针是如何工作的?,c++,templates,metaprogramming,C++,Templates,Metaprogramming,因此,remove\u引用或remove\u指针始终返回原语类型 我知道他们在模板元编程中使用所谓的模板专门化来实现这一点,但我不太明白如何实现 例如下面的例子 template<class T> struct AAA { typedef T Type; }; template<class T> struct AAA<T*> { // Why does T become int, not int * all of sudden? //
template<class T>
struct AAA
{
typedef T Type;
};
template<class T>
struct AAA<T*>
{
// Why does T become int, not int * all of sudden?
// How come does this get rid of '*' in a specific way?
typedef T Type;
};
int main()
{
AAA<int *>::Type MyVar = 3; // MyVar is not a pointer!
return 0;
}
模板
结构AAA
{
T型;
};
模板
结构AAA
{
//为什么不突然变成int,而不是int?
//这是如何以一种特定的方式去除“*”的?
T型;
};
int main()
{
AAA::Type MyVar=3;//MyVar不是指针!
返回0;
}
很明显,我在使用模板时遗漏了一些东西,或者一些指定的规则,我找不到任何好的文章来解释这一点
任何帮助都将不胜感激
谢谢你
// Why does T become int, not int * all of sudden?
T*
是int*
,所以T
必须是int
,T
在第二个特化中需要做什么,以便T*
匹配int*
?@gmannick我刚刚解决了这个问题。对不起,写错了。对不起,我甚至没看到那个打字错误。我不是这个意思。我的意思是在我给你的问题中填写<代码> T >代码,看看C++中的逻辑是如何工作的。要使T*
匹配int*
,T
需要是int
。这就是为什么T
在第二个专门化中是int
。