c++

How do you use stl's functions like for_each?

I started using stl containers because they came in very handy when I needed functionality of a list, set and map and had nothing else available in my programming environment. I did not care much about the ideas behind it. STL documentations were only interesting up to the point where it came to functions, etc. Then I skipped reading and...

Linkage Error with Inherited Class

I have static library and another program which uses it. In the static library If I define header without inheretence it works fine. class TcpCommunication On the other hand If I use inheretence with a QT class, class TcpCommunication:public QTcpServer I'm getting linkage error when I compiling code which uses this static library...

C and C++: Array element access pointer vs int

Is there a performance difference if you either do myarray[ i ] or store the adress of myarray[ i ] in a pointer? Edit: The pointers are all calculated during an unimportant step in my program where performance is no criteria. During the critical parts the pointers remain static and are not modified. Now the question is if these static ...

stdout and stderr character encoding

i working on a c++ string library that have main 4 classes that deals with ASCII, UTF8, UTF16, UTF32 strings, every class has Print function that format an input string and print the result to stdout or stderr. my problem is i don't know what is the default character encoding for those streams. for now my classes work in windows, later ...

Can't compile std::map sorting, why?

This is my code: map<string, int> errs; struct Compare { bool operator() (map<string, int>::const_iterator l, map<string, int>::const_iterator r) { return ((*l).second < (*r).second); } } comp; sort(errs.begin(), errs.end(), comp); Can't compile. This is what I'm getting: no matching function for call to ‘s...

How do I make a daemon into a stream in PHP

I have a daemon (written in C, but I assume it does not really matter) which outputs messages with printf, and can get input and do stuff with this input (again, not really important what, but he sends those messages to a different machine to be saved there in the DB). My question, how can I make this daemon to be a stream in PHP, so ...

Genetic programming in c++, library suggestions?

I'm looking to add some genetic algorithms to an Operations research project I have been involved in. Currently we have a program that aids in optimizing some scheduling and we want to add in some heuristics in the form of genetic algorithms. Are there any good libraries for generic genetic programming/algorithms in c++? Or would you rec...

C++ Template Classes Circular Dependency Problem

We have two classes: template<typename T, typename Size, typename Stack, typename Sparse> class Matrix and template<typename T, typename Size> class Iterator Matrix should be able to return begin and end iterators and Iterator will keep a referrence to the Matrix to access the elements via it's interface. We don't want Iterator t...

How to preselect Administrator when running an application using ShellExecuteEx with verb "runas"? (Windows XP)

I have an application which runs another application (mine) using the WinAPI "ShellExecuteEx" with the verb "RunAs" so that the other application should start with "Administrator" credentials. My OS is Windows XP. (Do not bother about other operating system, as I have specific code in place) The only problem with this thing is that the...

QTextEdit with different text colors (Qt / C++)

I have a QTextEdit box that displays text, and I'd like to be able to set the text color for different lines of text in the same QTextEditBox. (i.e. line 1 might be red, line 2 might be black, etc.) Is this possible in a QTextEdit box? If not, what's the easiest way to get this behavior? Thanks ...

C++ pointer to different array

Assume I have an array a and an array b. Both have the same type and size but different values. Now I create 3 or so pointers that point to different elements in a, you could say a[ 0 ], a[ 4 ] and a[ 13 ]. Now if I overwrite a with b via a=b - Where will the pointers point? Do the pointers still point to their original positions in ...

multiset & multimap - What's the point?

As the question states ... i don't get the point about multisets / multimaps. So, what's the purpose? ...

Windows message when mouse leave a control?

I have created a control and the mosemove for that control makes it change color, but I want to change it back to default when my mouse moves out of that control. I would have thought WM_MOUSELEAVE would do it but it didn't. Thanks ...

Can I detect (and warn on) redundancies at compile time?

Is there any way I can catch and warn about redundancies at compile time? Such as if (abc && abc) or if (def || def) Ok, this isn't actually from an optimisation point of view - I'm thinking more along the lines of a mistake in code - so when the coder intended to write if (abc && abc) when actually they meant to write if (a...

How do I extend mouse space in OpenGL windowed mode

How do I extend the distance the mouse can move in an OpenGL window? What I wish to achieve is an fps like interface where the cursor is hidden and camera rotations are not limited by the mouse having to remain inside the window boundaries. ...

Why isn't the boost::shared_ptr -> operator inlined?

Since boost::shared_ptr could be called very frequently and simply returns a pointer, isn't the -> operator a good candidate for being inlined? T * operator-> () const // never throws { BOOST_ASSERT(px != 0); return px; } Would a good compiler automatically inline this anyway? Should I lose any sleep over this? :-) ...

How do I bring a processes window to the foreground on X Windows? (C++)

I have the PID for the process (and the name), I want to bring it to the front on linux (ubuntu). On mac I would simply do SetFrontProcess(pid), on windows I'd enumerate the windows pick out the one I wanted and call SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); but I'm at a loss of what to do on linux. I've look...

Gradients for polygons in OpenGL

what is the best way to create a gradient for a 2D polygon in OpenGL, (Linear, and Radial)? Thanks How can you generate textures for radial gradients on the fly? ...

enumerate all combinations in c++

Possible Duplicate: Howto create combinations of several vectors without hardcoding loops in C++? My question is similar to this combinations question but in my case I have N (N > 4) small sets (1-2 items per set for now might go to 3 maybe 4) and want to generate each combination of one item from each set. The current soluti...

How can I compare the performance of log() and fp division in C++?

Hi, I’m using a log-based class in C++ to store very small floating-point values (as the values otherwise go beyond the scope of double). As I’m performing a large number of multiplications, this has the added benefit of converting the multiplications to sums. However, at a certain point in my algorithm, I need to divide a standard dou...