English 中文(简体)
C++ 模板类型是否为点人[复制]
原标题:C++ whether a template type is a pointer or not [duplicate]
This question already has answers here:
Closed 12 years ago.

Possible Duplicate:
Determine if Type is a pointer in a template function

我正在寻找一种方法,确定模板是不是在汇编时间的点。 由于T不是点子,方案将无法编纂,因为你不能删除正常类型的变量。

template <typename T>
void delete(T &aVar)
{
   // if T is a point
   delete aVar;
   aVar = 0;
   // if T is not a point, do nothing
}

基本上,我正在学习自己制定联系清单(而不是使用STL清单)。 我试图在我的名单上使用模板,以便它能够采取任何形式的行动。 当类型为点人时,我要自动删除(关键词删除)。

如上所述,当我使用名单上某类人员时,VC2010年赢得了汇编,因为你不能删除任何点变量。 因此,我正在寻求一种方法,例如,在删除枪支时要先从宏观上删除,或者不按照模板类型加以汇编。

最佳回答

这是一种手法,但我认为,在使用本地的<代码>delete后,更宜使用NUL

只考虑对可变点人类型论点的职能,使用

template< typename T > // The compiler may substitute any T,
void delete_ref( T *&arg ); // but argument is still a pointer in any case.

简单地发现某一类型是否为点人,使用is_pointer from <type_traits> in Boost, TR1, or C++0x。

问题回答

如何将这一职能带进T*而不是T?





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签