English 中文(简体)
将物体列入清单,c++
原标题:Inserting objects into a list, c++
  • 时间:2011-11-10 20:32:52
  •  标签:
  • c++
  • list

我正试图在C++中编制一份包含几何数据的清单。 清单是三角名单:

class Triangle
{
public:
Triangle(Point P1,  Point P2,  Point P3);
Triangle(const Triangle& T);
~Triangle() {delete e1; delete e2; delete e3;}



const Triangle operator=(const Triangle & T);

bool InCircle(Point & P);
int TriNumber() { return TriangleNumber;}
void SetTriNumber(int trinum) { TriangleNumber = trinum;}
Edge ReturnEdge(int i);
Point ReturnPoint(int i);





protected:
Point p1,p2,p3;
Edge *e1, *e2, *e3; 
int TriangleNumber;             
};

然而,当我试图制定三角名单时,我会利用以下线出现分裂:

const Point p1(100.0, 100.0);
const Point p2(-100.0, 100.0);
const Point p3(0.0, -150.0);



Triangle TT(p1,p2,p3);

list<Triangle> trilist;
list<Triangle>::iterator iter;
iter = trilist.begin();
// the next line is causing all the problems:
trilist.insert(iter, TT);

非常感谢任何帮助。

问题回答

请记住STL集装箱将你带入的物体。 (见Scott Meyers, 项目3)

如果您的物品不能妥善复制,那么,如果你将其装入集装箱,那么你就将充其量地错,而且最坏的是微妙的 b。 (As Meyers notes, “Copy in,cop out.) ——————

由于你的目的似乎意味着动态分配在某些地方进行,我猜测,你的一个班级的影印机、派任操作员或司机没有得到适当执行。

根据您对复印件施工商和投递商的履约情况,有可能将 Edge号(*e1,*e2,*e3删除不止一次。

我们能够看到这些建议的执行情况?





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

热门标签