English 中文(简体)
1. 自动分解物体?
原标题:Auto detaching objects?
  • 时间:2010-08-12 17:06:12
  •  标签:
  • c++

I have a mother class that stores the pointers to some objects in a list. I want these objects to detach themselves from the list when they are destroyed. Can anyone suggest some good ways to do this please?

最佳回答

www.un.org/Depts/DGACM/index_spanish.htm 粗略方式是将集装箱(或点)放在清单上的物体上,并将其移走到其航道上:

class Contained;
class Container {
  std::list<Contained*> children;
public:
  ...
  void goodbye(Contained*);
};
class Contained {
  Container& c; // you set this in the constructor
public:
  ~Contained() { c.goodbye(this); }
};

请注意,这使得<代码> 含有 类别不可复制。

www.un.org/Depts/DGACM/index_spanish.htm “中获取<> > 所载的舱位,从<条码>上获取<条码>;在集装箱内取得“控制”的。 一旦所装物体被删除,<代码>QPointer将定为零。

或者,如果你使用诸如<代码>boost”等一些记忆管理设施:共享_pointer,(我假定集装箱确实有<>条码/条码>的物体,否则,当儿童物体死亡时,它会最了解情况),那么你将使用<条码>Container中的弱小点,该代码具有类似功能。

问题回答

您可以在这些班级和称为“主子”时,增加母亲班的参考/点。 序号:





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

热门标签