English 中文(简体)
注:
原标题:boost::bind and delete

我需要绘制<代码>delete ptrAddr; to a boost:Function0,但有一些麻烦去做。 免费工作只得罚款。 这个问题看来是<代码>std:ptr_fun(operator切除),但可以不写助手,说明如何做这项工作。

boost::function0<void> Function;
Function = boost::bind(std::ptr_fun(free), (void*)malloc_string);  //this works
Function = boost::bind(std::ptr_fun(operator delete), (void*)new_string);  //doesn t work
Function();  //call function
最佳回答
问题回答

<代码>delete p;不是功能呼吁;expression。 你们想要的是什么。

确实有自由功能的<代码>:操作员删除(<>>/代码>,但这是你认为的。

看看任何标准图书馆集装箱(关键词:分配器)或或许<代码>的使用情况:unique_ptr,看一看如何处理可定制物体的删除。


典型的建筑/建筑顺序细分为碎块:

void * addr = ::operator new(sizeof(T));  // allocation

T * p = ::new (addr) T;                   // construction

p->~T();                                  // destruction

::operator delete(addr);                  // deallocation

The first to steps are morally equivalent to the expression T * p = new T;, while the last to correspond to delete p;. There is no way to call a constructor other than through a new expression, though; and you mustn t forget to invoke the destructor one way or another.





相关问题
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?

热门标签