c++

Constructor for a no-named struct

Hi! I have a class something like that: template <class T> class bag { public: private: typedef struct{void* prev; struct{T item; unsigned int count;} body; void* next;}* node; typedef struct{ node operator->() { return current; } operator(){;} // <- i can not do that, right? private: node current; } iterator; //... }; S...

Optimize Concurrent writes to a buffer

Hi, I am required to have multiple threads writing to a single buffer (contiguous chunk of memory). The brute force method will be as follow The thread that wants to write to buffer will acquire lock on the buffer Entire buffer is locked and therefore only the thread that acquired lock can modify the buffer. The thread write to buffer...

Why bother to write -> rather than . ?

Possible Duplicate: Why does C have a distinction between -> and . ? What is the real reason for a programmer to have to differentiate between . and -> when accessing a member of an object? void foo( Point &p ) { p.x ; p->y; // syntax error } void foo( Point *p ) { p.x ; // syntax error p->y; } I mean, on...

QImage file path

I don't see this in the documentation anywhere, so it probably doesn't exist, but just in case: I have a function that accepts as a parameter a vector of QImages. Each QImage was loaded from disk at some point and has not been edited--it is just read from. Ideally what I'd like to do is loop over all the QImages and output a list of the...

Obscure compiler error on piece of beginner C++ code

Hello guys, g++ is letting out an obscure error, undefined reference to '__gxx_personality_sj0' in two lines of my project. What does this mean in this context? I googled a lot and found out this is usually related to the inclusion of C code in C++ or something like that, which is not what I'm going for. (I know the code isn't high qual...

Does hash_map automatically sort [C++]??

In the below code, hash_map is automatically sorting or maybe inserting elements in a sorted order. Any ideas why it does this?? Suggestions Please?? This is NOT a homework problem, trying to solve an interview question posted on glassdoor dot com. #include <iostream> #include <vector> #include <ext/hash_map> #include <map> #include <st...

istream not working in DEV C++

Hi. I'm using ifstream and ofstream operations in DEV c++ but they don't seem to work correctly. I've been trying to write a little prime generator code but it doesn't work :\ When I display fstream::tellg() at any point, it displays -1. Please check the code. Thanx. #include<iostream> #include<math.h> #include<fstream> using namespace ...

In which order does the linker process the library directories?

It is possible that more than one instance of the library exists in the search path during compilation. In what order will linker process directories included in the search path? The platform in question is Sun OS. ...

Pass character stream to libxml2

Hi, I have a XML document which is received as a character stream. I wish to parse this using libxml2. Well one way would be to save it as an .xml and then open it using one of the libxml2 API's. Is there a way i can directly build a tree on this stream and parse it ? Env is purely c++/c. Cheers! ...

ActiveX HWND, DirectX WindowLess mode

Hi. I would like to render video in ActiveX control (not in pop-up DirectShow window). I have: IID_IVMRWindowlessControl IID_IVMRFilterConfig9 CLSID_VideoMixingRenderer9 I would like to set WindowLess mode, but I don't know how to get HWND of..., exactly, of what? IEFrame, HTML element? hr = pWc->SetVideoClippingWindow(???); Anyo...

Is va_start (etc.) reentrant?

While making an edit to a class with a long history, I was stymied by a particular habit of the architect of wrapping his va_start -> va_end sequence in a mutex. The changelog for that addition (which was made some 15 years ago, and not revised since) noted that it was because va_start et. all was not reentrant. I was not aware of any ...

2D Bounding box collission

Hi, i'm having some problems with collission in a small 2D game i'm writing. I'm currently working on a function that i want to find if the player character collides with a block, and which side of the block he collided with. Currently i have something like (psuedo-code): if(PLAYER_BOX IS WITHIN THE BLOCKS Y_RANGE) { if(PLAYER_BOX_...

subdirs template in Qt

Hi. I'm trying to create project structure like below test/ test.pro build/ build.pro main.cpp gui/ gui.pro mainwindow.h mainwindow.cpp My test.pro looks like this: TEMPLATE = subdirs SUBDIRS = gui CONFIG += ordered SUBDIRS +=build build.pro TEMPLATE = app QT += core gui SOURCES += main.cpp LIBS += -L../gui gui.pro TE...

Does && in c++ behave the same as && in Java?

Hi guys, my question is essentially in the title. Basically I've learned that in Java the && operator acts like a short circuit, so that if the first condition evaluates to false it doesn't look at the rest of the statement. I assumed this was the case in c++ but I'm writing a bit of code which first checks that an index has not exceeded...

Size of class instance

I'm working with a class for which the new operator has been made private, so that the only way to get an instance is to write Foo foo = Foo() Writing Foo* foo = new Foo() does not work. But because I really want a pointer to it, I simulate that with the following : Foo* foo = (Foo*)malloc(sizeof(Foo)); *foo = Foo(); so that ca...

Anyone know of a Daitch-Mokotoff implementation in Objective-C / C++ / C?

I want to compare user inputs with a string from a database. As I expect users to misspell all the time, I want to compare with a certain amount of slack. Apparently, Daitch-Mokotoff have developed a system that is rather precise, more so than Soundex. Does anyone know of an implementation of this system that will run on an iPhone (pre...

STL iterator into constructor

Id' like to know how to write a constructor for a custom class (a linked list in this case) that accepts any STL input iterator. I have already created a custom Iterator class which is tied to my List class. This works fine. template <typename T> List<T>::List(Iterator beg, Iterator end) : first_(0) { while (beg != end) ...

Read and copy file with EOF indicator in the middle

Hi, I used the code below to copy from one binary file to another, but the first file contains some EOF indicators (0xFF) as part of it, so the copy function actually copies the file until its first EOF indicator. For example: if my file is {0x01, 0x02, 0x03, 0xFF, 0x01, 0x02, 0xFF, 0xFF} then only {0x01, 0x02, 0x03} will be copied to ...

vector resize() automatic fill

Hi everyone, I'm writing a class that holds a matrix (of double values), represented as vector<vector<double>>; I want to implement the operator=, to re-fill my matrix with the details of a given sparse matrix. I'm writing the following code: RegMatrix& RegMatrix::operator=(const SparseMatrix rhs){ if(*this != rhs){ _matri...

What is POI and what does it mean?

What is POI? I have seen this term being used several times in context of C++ Templates. What does it mean? ...