Is there anything wrong with pushing back a vector of vectors? like
typedef vector<Point> Polygon;
vector<Polygon> polys;
polys.push_back(some_poly);
All the elements in some_poly will be copied right?
I have a bug in my code and I can't seem to figure out what's wrong with it.
...
Which one is better:
public:
const vector<int> & GetPointsVector();
private:
vector<int> PointsVector;
Or:
public:
int GetCurrentPoint();
void MoveToFirstPoint();
void MoveToNextPoint();
bool IsAtLastPoint();
size_t GetNumberOfPoints();
private:
vector<int> PointsVector;
...
Hi, I have two vectors of floats and i want them to become one vector of Complex numbers. I'm stuck. I don't mind using iterators, but i am sure it'd be rediscovering the wheel i'm not informed about. Is my code leading me in the right direction?
typedef std::vector<float> CVFloat;
CVFloat vA, vB;
//fil vectors
typedef std::complex<CVFl...
What's the best way in C++ to copy a pair from a map to vector? I'm doing this so I can subsequently sort the vector.
...
I have a bunch of strings that I need to sort. I think a std::vector would be the easiest way to do this. However, I've never used vectors before and so would like some help.
I just need to sort them alphanumerically, nothing special. Indeed, the string::compare function would work.
After that, how can I iterate through them to verify ...
Hi,
I am having quite a bit of trouble with trying to push_back an object of my custom class to a vector of pointers with my custom class as the type. Please see the code below along with the error received. I am using Eclipse with the CDT plugin and OpenCV on windows xp.
I have spent so much time trying to find an answer but to no ava...
I have three vectors V1, V2, and V3. Their origin points are on the axes' origin. How could I determine whether V3 is between V1 and V2 when I move around counterclockwise from V1 to V2?
It can't be done with obtaining their angles and evaluating these kind of conditions (pseudo-code):
if angle(V3) > angle(V1) && angle(V3) < angle(V2...
I have a Point on the surface of the earth which I am converting to a Vector from Earth Center.
I have a True North Heading in degrees describing the path the point will travel on the surface of the earth.
I need to calculate a Vector which is perpendicular to the plane created by the path of this point along the earths surface.
I hav...
As most of you may be following my line of questions already know, i'm trying to create a program that can serialize multiple structs to a .dat file, read them back in via loading it's serialization, edit the contents, and then re-write them to the file and so on. It's a inventory program I am trying to do and I can't get it to work for ...
If I type in
Description: Apple
Quantity: 10
Wholesale Cost: 30
Retail Cost: 20
Date Added: December
These are the contents in my .dat file:
1Apple103020December
But when I load my program, it doesn't load the struct back in correctly resulting in there being 0 items in my list. Is that what it is suppose to look like or am I do...
Suppose you have a function 'normalize' which takes a list of numbers (representing a vector) as input and returns the normalized vector. What should the result be when the vector is all zeros or the sum of its components is zero?
...
I have a std::vector with n elements. Now I need to pass a pointer to a vector that has the last n-1 elements to a function.
For example, my vector<int> foo contains (5,2,6,87,251). A function takes vector<int>* and I want to pass it a pointer to (2,6,87,251).
Can I just (safely) take the iterator ++foo.begin(), convert it to a pointer...
I'm writing some C++ code that manipulates a bunch of vectors that are changing in size and are thus being reallocated constantly.
I would like to get a "pointer" into these vectors that remains valid even after reallocation of the vector. More specifically, I just want these "pointers" to remember which vector they point into and the ...
For Windows XP / Windows Server 2003
I'm trying to print an EMF(or WMF) file format to the virtual printer "Microsoft XPS Document Writer" using Windows Picture and Fax Viewer (shimgvw.dll) from the command line. I want the resulting XPS to be in vector format, like the WMF/EMF is.
It works with all image formats except WMF and EMF...
In C++, I believe, a better way of dealing with reallocation is to use a STL vectors, as it guarantees the contiguous storage locations.
I have couple question to understand the difference:
Is there any scenario in which I need to prefer realloc over vector ?
Is there anything else ( apart from vector ) which is equivalent to realloc...
Hi,
I have a question regarding vectors:
If I have a std::vector<MyClass> will this vector "inherit" the MyClass member functions or not? If not, then would be the best way to handle individually the MyClass members inside a loop? Would I have to create a new class object on each iteration and assign the current vector iterator to it?
...
I am working on a merge sort function. I got the sort down - I am trying to get my merge part finished. Assume that I am learning C++, have cursory knowledge of pointers, and don't understand all the rules of std::vector::iterator's (or std::vector's, for that matter).
Assume that num is the size of the original std::vector that have c...
No doubt some of you have seen my recent posting, all regarding the same program. I keep running into problems with it. To reiterate: still learning, not very advanced, don't understand pointers very well, not taking a class, don't understand OOP concepts at all, etc. This code just merges two sorted vectors, farray and sarray, into a si...
i'd like to perform element-wise functions on boost matrix and vector types, e.g. take the logarithm of each element, exponentiate each element, apply special functions, such as gamma and digamma, etc. (similar to matlab's treatment of these functions applied to matrices and vectors.)
i suppose writing a helper function that brute-force...
In terms of performance, what would work faster? Is there a difference? Is it platform dependent?
//1. Using vector<string>::iterator:
vector<string> vs = GetVector();
for(vector<string>::iterator it = vs.begin(); it != vs.end(); ++it)
{
*it = "Am I faster?";
}
//2. Using size_t index:
for(size_t i = 0; i < vs.size(); ++i)
{
//...