vector

Accessing an object's attributes correctly out of a vector and clearing it out

I'm unfamiliar with OO in C++. I've been pushing instances of the MyPoint class into vector <MyPoint> trianglePoints; like this: trianglePoints.push_back(MyPoint(x,y)); This is my definition of MyPoint: class MyPoint { public: float x; float y; MyPoint(float x, float y) //constructor { this->x=x; ...

Why am I getting vector iterators incompatible?

I'm doing the following and getting that debug error: AguiWidgetBase* AguiWidgetContainer::recursiveGetWidgetUnderMouse( AguiWidgetBase* root, const AguiMouseEventArgs &mouse) { AguiWidgetBase* currentNode = root; bool foundsomething = true; while(foundsomething) { foundsomething = false; if(current...

Direction angle or pointing a 3D angle to a position in space.

Hello. I'm trying to point an entity to a 3D vector. (basically setting an entities angle so it points to a position in 3D space). At the moment, I'm stuck with getting an angle from a vector. //Vectors in the bracket are 3D, first is the entity position, second is a position in space where I want to point at. ( myEntity.Pos - posToPoi...

What is a ray intersection interval?

In the context of ray/box intersection, what exactly is "a valid intersection interval"? I've been searching through different tutorials, but it seems they mostly seem to expect this as a priori knowledge. ...

Prevent last element in char * vector from changing

I am reading strings in C++ using fread where I am reading and storing shortSiteText in siteNames_. siteNames_ is declared as std::vector<char*> siteNames_; I use siteNames_ in other functions but because shortSiteText is a pointer, when I call the delete command on it, the last entry in siteNames_ is changed. How do I prevent this? fo...

Why does the OpenCL vector addition Nvidia SDK example use async writes?

The vector addition example has this code: // Asynchronous write of data to GPU device ciErr1 = clEnqueueWriteBuffer(cqCommandQueue, cmDevSrcA, CL_FALSE, 0, sizeof(cl_float) * szGlobalWorkSize, srcA, 0, NULL, NULL); ciErr1 |= clEnqueueWriteBuffer(cqCommandQueue, cmDevSrcB, CL_FALSE, 0, sizeof(cl_float) * szGlobalWorkSize, srcB, 0, NULL,...

pointer to std::vector of arbitrary type (or any other templated class)

Hi! let's say i want to have a member variable for a pointer to std::vector but i do not want to specify what type of variable it stores. I want to access only those functions that are independant of it's actual generic type. is this possible with c++? something like this: class Foo{ public: void setVec(std::vector* someVec){ ...

Sending C strings and vectors to MurmurHash gives inconsistent results.

I'm trying to use MurmurHash (returning 64 bit hashes on a 64bit comoputer) and have sent it the simple 3 letter string 'yes' as follows char* charptr = "yes"; cout << MurmurHash64A(charptr, 3, 10); (where 3 is the length and 10 is the seed) This gives a 64bit hashed response as expected, I can set up more pointers to C strings holdin...

c++ std::vector Orphan Range error

A program dealing with graphs(from graph theory) representation and transformation.The adjacency list and matrix are implemented like dynamic arrays of vectors(don't ask why not vector of vector) for the following function program exits with memory error and compiler pointing to the orphan vector definition. int vertex,edges; vector<int...

How bad is to use void pointer in std::vector declaration?

I have to different classe: class text { }; class element { }; And I want to store them in the class node: template <typename T> class node { T cargo; std::vector<void*> children; node(T cargo) : cargo(cargo) { }; void add_child(T node) { this->children.push_back((void*) node); } } So I would...

comparison operator

hi, It may be silly question. Is there any way to give comparison operator at runtime using string variable. Suppose i have a data of salaries in vector. vector < int > salary; Input: salary[i] != /* ==,>,<,>=,<= (any comparison operator)) */ 9000. The input given like above. I store the comparison operator in string str. str = (an...

c++ vector How to change internal pointer

hi guys, I would like to serialize vector. And dunno how to change pointer of vector.. To make it simple let's say I have a vector smt like: vector<char> v; And I have this pointer: char* c = { 'v', 'e', 'c', 't', 'o', 'r' }; And I would like my vector v's internal pointer points my char* c: &v[0] -> c How can I adjust vector...

std::vector iterator incompatibles

I have an error (vector iterator incompatibles) during execution in my C++ program that I do not understand. [ (Windows / Visual C++ 2008 Express) ] Here is a simplified version of my problem : #include <vector> class A { int mySuperInt; public: A(int val) : mySuperInt(val) {} }; class B { std::vector<A*> myAs; public:...

Extract Geometry from Font

I'd like to be able to extract the geometry for each letter in a TrueType font file. Each letter would have a set of coordinates, assuming each letter is in its own grid. As a picture tells a thousand words - I'd like to get the vertices for letters similar to the image below (courtesy of http://polymaps.org/) Update Thanks to the ...

Advantages of using arrays instead of std::vector?

I'm currently seeing a lot of questions which are tagged C++ and are about handling arrays. There even are questions which ask about methods/features for arrays which a std::vector would provide without any magic. So I'm wondering why so much developers are chosing arrays over std::vector in C++? ...

std::vector push_back is bottleneck

Here is what my algorithm does: It takes a long std::string and divides it into words and sub words based on if it's greater than a width: inline void extractWords(std::vector<std::string> &words, std::string &text,const AguiFont &font, int maxWidth) { words.clear(); int searchStart = 0; int curSearchPos = 0; char rig...

What is the best method to compare two vectors of CString

Hi I am trying to find the most efficient, optimized and fastest way to compare to std vectors of CString. the strings in question are case-sensitive. I have tried using the == operator for the vector container but this sometimes return false positives. I mean for instance if one vector contains elements in the order (a,b,c) and the oth...

back_insert_iterator with remove_copy_if

I am trying to use a back_insert_iterator with remove_copy_if using vectors but I have compile errors. Do you know why the code below is wrong? #include <iostream> #include <string> #include <algorithm> #include <cassert> #include <vector> #include <iterator> #include <functional> struct checkRem : std::unary_function<int,bool> { ...

How does one compute the sum of a 1D array with BLAS?

In BLAS level 1 there are *ASUM and *NRM2 that compute the L1 and L2 norms of vectors, but how does one compute the (signed) sum of a vector? There's got to be something better than filling another vector full of ones and doing a *DOT... ...

Is pointer better than instance when declaring members in class?

Option 1: class B{//}; class A { public: void Funcs(); private: std::vector<A> vecA; }; Option2: class B{//}; class A { public: void Funcs(); private: std::vector<A*> vecpA; }; Which one is better, is there any guidelines? ...