如何“解引用类型”在C ++ 03? [英] How to "dereference a type" in C++03?
问题描述
如何在C ++ 03中获得另一种类型的引用类型?注意,它可以是其他可解引用的类型,如 std :: vector< int> :: iterator
。
How do I get the "dereferenced type" of another type in C++03? Note that it can be other dereferenceable type like std::vector<int>::iterator
.
如果我有
template<typename T>
struct MyPointer
{
T p;
??? operator *() { return *p; }
};
如何知道如何替换?
与?
How can I figure out what to replace the ???
with?
(没有升压!我想知道如何自己弄明白。)
(No Boost! I want to know how to figure it out myself.)
推荐答案
在一般情况下,你不能。对于原始指针,您可以部分专门化,如其他答案所示 - 自定义智能指针可能有一个常见的typedef为结果类型。但是,你不能写一个单独的函数来处理C ++ 03中的任何指针。
In the general case, you can't. For raw pointers, you can partially specialize as shown in other answers- custom smart pointers may have a common typedef for the result type. However, you cannot write a single function that will cope with any pointer in C++03.
这篇关于如何“解引用类型”在C ++ 03?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!