c++

Is C really faster than C++?

At begning I used to believe, since C++ is superset of C, there should'nt be a reason for C++ being slower than C but many people on SO dont think so http://stackoverflow.com/questions/2245196/c-urban-myths/2245221#2245221. Is it true that C++ is slower than C? If not, why to use C anyway? ...

Portable branch prediction hints

Is there any portable way of doing branch prediction hints? Consider the following example: if (unlikely_condition) { /* ..A.. */ } else { /* ..B.. */ } Is this any different than doing: if (!unlikely_condition) { /* ..B.. */ } else { /* ..A.. */ } Or is the only way to use compiler specific hints? (e.g....

Pre Z buffer pass with OpenGL?

How exactly can I do a Z buffer prepass with openGL. I'v tried this: glcolormask(0,0,0,0); //disable color buffer //draw scene glcolormask(1,1,1,1); //reenable color buffer //draw scene //flip buffers But it doesn't work. after doing this I do not see anything. What is the better way to do this? Thanks ...

Complete example of wxwidgets custom event passing string data

I am receiving messages from the network on a non-GUI thread and need to use wxEvtHandler::AddPendingEvent to tell the GUI to update accordingly. I also need to pass data to my GUI code so that it can act apropriately. I believe I have to create a custom event, but haven't found a straightforward implementation. This closest thing that ...

Defining a Static 2-dimension Array with Inline Function

I setup a class with: class Example { static const float array[3][8]; }; and implemented inline const float below_center(const float pos) { return pos - (size / 2); // size is a const float } inline const float above_center(const float pos) { return pos + (size / 2); } inline const float *set_pos(const float x, const fl...

how to create a data structure with run time limits

hello i need to implement a data structure that supports insertion deletion and search in O(log(n)) and extracting a special object in O(1) my Data structure needs to hold vehicals sorted by their ID and every vehical got a field which represents the time until the next care. i need to extract the vehical that needed to be cared next in...

C++ vector, return vs. parameter

Possible Duplicate: how to return an object in C++ I am wondering if there is a difference between the three following approaches: void FillVector_1(vector<int>& v) { v.push_back(1); // lots of push_backs! } vector<int> FillVector_2() { vector<int> v; v.push_back(1); // lots of push_backs! return v; } vector...

Infinite Thread that may or may not run a CDialog each loop

I am working on a MFC project where I need a separate loop that will run continually or once every few seconds, and each time it may or may not need to run a Dialog to get some input from the user. I was thinking of using AfxBeginThread, but from what I have read about it, it doesn't really work with a continuous loop. ...

Managing COM type library as a dependency.

We have a win32 unmanaged application that has an API we distribute as a type library. Several other applications we build depend on the TLB from the legacy application being registered to build. Each product is still under active development, including the items exposed/accessible to the type library. While trying to find the best ...

c++: Is checking current thread inside a function ok?

Is it ok to check the current thread inside a function? For example if some non-thread safe data structure is only altered by one thread, and there is a function which is called by multiple threads, it would be useful to have separate code paths depending on the current thread. If the current thread is the one that alters the data struc...

Is anyone using Maven/NAR for any large scale C/C++ projects?

And, what has your experience been? Do you think that Maven has been well suited to your project, and how would you advise others on following your path? Thanks in advance! ...

Specifying one type for all arguments passed to variadic function or variadic template function w/out using array, vector, structs, etc?

I'm creating a function (possibly member function, not that it matters... maybe it does?) that needs to accept an unknown number of arguments, but I want all of them to be the same type. I know I could pass in an array or vector, but I want to be able to accept the list of args directly without extra structure or even extra brackets. I...

Reading and writing C struct from embedded lua

I'd like to embed lua to allow scripting in my C++ application. In particular, I have two structs which I'd like to pass as arguments to a given lua function. One will be read-only, the other will be read/write. Highly simplified examples of these structs follow: struct inData { int x; int y; //many other fields follow }; s...

Remote controlling Windows Media Center

I am interested in building a remote control app of sorts for android devices to allow them to control windows media center on windows 7. How can I send commands to media center as if they were coming from a physical remote? Lets say for instance I wanted to change the TV to channel 67, how would I do that code wise? I would prefer to...

static members and consts

class a { protected: const int _ID; public: a::a(int id){}; a::top(int num); }; class b : public a { static int ok; b::b(int id):a(id){}; a::top(ok); } int main() { int t=5; b opj=b(t); } first why i get this compile error that solved only when i remove the const non-static const member ‘const int Student::_ID’, can...

sorting pixels in a ppm file (C++)

i need help with the coding of a program that will read a ppm file using command line arguments ( name of the ppm, name of output ppm) what it has to do is, open the file read and store the dimensions of the image and the pixel data. There are 3 channels in a given pixel with max values of 255. must be compatible with binary bytes of d...

C++ dequeue vs vector and C++ map vs Set

hi, Can some one please tell me what is the difference between vector vs dequeue. I know the implementation of vector in C++ but not dequeue. Also interfaces of map and set seem similar to me. What is the difference between the two and when to use one. ...

C++ remove character from string

Hi! I am currently trying to implement deleting characters from a text field in C++. If the user hits Backspace, the following code is executed. There is currently no cursor, it should just remove the last character... if (mText.length() > 0){ mText.erase( mText.length() - 1, 1); // mText.resize(mText.length() - 1); } This wo...

Extra digits with printf Hex

Why do I get extra digits after the string of Hex digits when using printf? cout << printf("%06X ", 0xABCDEF); produces: ABCDEF 7 So where does the 7 come from and how can I get rid of it? ...

"Matrix decomposition" of a matrix with holonic sub structure

Before I start, I must say that for those with a background of linear algebra, this is NOT matrix decomposition as you know it. Please read the following paragraphs to get a clearer understanding of the problem I am trying to solve. Here are the salient properties/definitions of the matrix and its submatrices: I have an SxP matrix whi...