vector

Does the "delete" statement doubly free an object?

Hello C++/STL gurus: Does the "delete" statement below "doubly free" an object? (...object_list is a global vector<object*>...) vector< object * >::iterator it, eit, iter; object *p_object; vector< object * > dead_objects; it = object_list_.begin(); eit = object_list_.end(); //---collect pointers of all dead objects to d...

Passing an iterator to a function

Looking through the source code of a binary tree,I find the following function: //definition of BTR,in case you'd want to know template< class Type> struct BTR { // The item saved to that specifiec position into the tree Type value; // Points to the left leaf BTR<Type>* left; // Points to the right leaf ...

Vectors in Cocoa Touch / Objective-C

Hi all, Is it possible to use vectors in Coca Touch? If so, what library must be included? I was following a general C tutorial on them an the only thing needed was to #include <vector> But XCode states that there is no such file or directory. Any pointer to a library that provides such functionality is appreciated. Regards ~dhp ...

different types of objects in the same vector array ?

Hi , I am using an array in a simple logic simulator program and I want to switch to using a vector to learn it but the reference I am using "OOP in C++ by Lafore" doesn't have a lot about vectors and objects so I am kinda of lost . Here is the previous code : gate* G[1000]; G[0] = new ANDgate() ; G[1] = new ORgate; //gate is a class i...

Example to use shared_ptr ?

Hi I asked a question today about How to insert different types of objects in the same vector array and my code in that question was gate* G[1000]; G[0] = new ANDgate() ; G[1] = new ORgate; //gate is a class inherited by ANDgate and ORgate classes class gate { ..... ...... void Run() { //A virtual function } }; class ANDga...

C++ vector::clear

vector <weight> decoy; void clear_decoy() { decoy.clear(); vector<weight> (decoy).swap(decoy); } In the above method clear_decoy(), what does vector<weight> (decoy).swap(decoy); mean please? Does the method clear decoy or not? Thanks! ...

C++ Vector/list of priority queues?

Why wouldn't C++ allow something like that ? I need to have multiple priority queues, the number of which would be determined at run time. This fails to compile std::vector<std::priorityqueue<Class A>>. Is there a better approach ? ...

template class & vector

Implement a template class named MyStack that creates a stack using STL class vector. MyStack class will have two functions – push() and pop(). Since MyStack is a template class, it must be written in such a way that it can be used to create stack of any type of data (both built-in and custom type). When an element of the stack is popped...

Open source .Net vector graphics editor

Does anyone know of any open source vector editors written in a .Net language? I know Inkscape is very popular, but it is written in c++. The only .Net one I know of is XDraw, but would like something more active or with more features. Thanks. ...

what median_unsafe in C++ mean

Hi, I run into a C++ code: vector<double> PITs; if(PITs.size() > 0) PIT = util::median_unsafe(PITs); What is mean by util::median_unsafe, why I cant find it in C++ reference? thanks ...

Multidimentional Vector in AS3

How can I initialise two-dimentional typed Vector is AS3? Now I can get working only this: private var _mainArray : Array = new Array( MyConst.DIMENTION ); public function MyArray() { for ( var i : int = 0; i < MyConst.DIMENTION; i++ ) { _mainArray[ i ] = new Vector.<int>( MyConst.DIMENTION ); } } ... _mainArray[...

Erasing multiple objects from a std::vector?

Here is my issue, lets say I have a std::vector with ints in it. let's say it has 50,90,40,90,80,60,80. I know I need to remove the second, fifth and third elements. I don't necessarily always know the order of elements to remove, nor how many. The issue is by erasing an element, this changes the index of the other elements. Therefore,...

Does insertion of elements in a vector damages a pointer to the vector ?

In a program to simulate logic gates I switched from using arrays node N[1000]; to vectors vector<node> N; And my program did work perfectly before using vectors but now it prints wrong results, so I tried debugging and I found out that the bug happens here: node* Simulator::FindNode(string h) { int i; for(i = 0; i < NNo...

How does this work?

In applications like Adobe Illustrator, they have a way to simplify a path. I'm not sure how this works exactly. Given a path with points which have 2 bezier handles each (for cubic bezier), how could I go about simplifying the path? Thanks ...

Help with understanding this algorithm

I would like to implement the Ramer–Douglas–Peucker_algorithm in C++. The pseudo code looks like this: function DouglasPeucker(PointList[], epsilon) //Find the point with the maximum distance dmax = 0 index = 0 for i = 2 to (length(PointList) - 1) d = OrthogonalDistance(PointList[i], Line(PointList[1], PointList[end])) if d > ...

Can a std::vector be ='d to another std::vector?

Say I have the following: std::vector<int> myints; and then I have a function that returns an int vector: std::vector<int> GiveNumbers() { std::vector<int> numbers; for(int i = 0; i < 50; ++i) { numbers.push_back(i); } return numbers; } could I then do: myints = GiveNumbers(); would doing this safely make it so that myints ...

Simplifying a cubic bezier path?

I'm trying to achieve something close to what Adobe Illustrator does with the brush tool. It correctly analyzes and simplifies the path, including its bezier handles. I implemented the Ramer–Douglas–Peucker_algorithm however, it wound up not really being what I needed. It works very well for line segments, but doesn't factor in bezier ha...

What would this look like as pseudocode?

I'm trying to implement this: from https://docs.google.com/viewer?url=http://www.tinaja.com/glib/bezdist.pdf&amp;pli=1 The following BASIC program uses the method of finding distance. The program also searches for the minimum squared distance between points and a curve. REM BEZIER.BAS JIM 20DEC92 12:37 DATA 2,3,5,8,8,14,11,17,14,17,16,...

Why only one object gets constructed but multiple objects are destroyed when using functor?

The following example, beats me. I've been so far thinking, that when functor is being used, the object gets constructed once and the same object is used multiple times, when used with for_each algorithm and that seems to be correct. However, even though, only one object gets constructed, but multiple objects are destroyed. Now, this b...

Check whether a line-segment intersects the perpendicular line draw from a particular point?

As shown in this image: I have a set of line segments. I want to check which line-segments intersect with the perpendicular line drawn from a given point (x0,y0). (E.g.: AB passes the check and BC does not.) The only information I've got is two points of the line-segment, (x1,y1), (x2,y2), and the target point (x0,y0). Is it possi...