c++

C++ bit shifting

Hi, I am new to working with bits & bytes in C++ and I'm looking at some previously developed code and I need some help in understanding what is going on with the code. There is a byte array and populating it with some data and I noticed that the data was being '&' with a 0x0F (Please see code snipped below). I don't really understand ...

Uniquely identifying one of an active active server pair

I've got two servers in active active configuration sharing a clustered database. One operation will be to tidy up the database (e.g. delete old records etc) which I only want one server to perform at a time. I am currently planning on writing a configurable value into the dB so that one server can id if the other server is working on t...

fstream file I/O question - when to close a file stream

Hi, I am trying to work out if I need to call close on a fstream object if the intial open failed. i.e. std::fstream strm; strm.open( "filename" ); if( ! strm.fail() ) { // Do something strm.close(); // [1] } strm.close(); // [2] Where should close be called here - should it always be called [2] or only if the open succ...

Why was std::strstream deprecated?

I recently discovered that std::strstream has been deprecated in favor of std::stringstream. It's been a while since I've used it, but it did what I needed to do at the time, so was surprise to hear of its deprecation. My question is why was this decision made, and what benefits does std::stringstream provide that are absent from std:...

Visual C++ - Memory Leak Detection

Any suggestions? This SO post talks about Visual Leak Detector, but I'm looking for other tools. Also, please don't recommend this. ...

abort, terminate or exit?

What's the difference between those three, and how shall I end program in case of exception which I can't handle properly? ...

Qt/C++ regular expression library with unicode property support

I'm converting an application from the .Net framework to Qt using C++. The application makes extensive use of regular expression unicode properties, i.e. \p{L}, \p{M}, etc. I've just discovered that the QRegExp class lacks support for this among other things (lookbehinds, etc.) Can anyone recommend a C++ regular expression library that:...

Class members allocation on heap/stack? C++

If a class is declared as follows: class MyClass { char * MyMember; MyClass() { MyMember = new char[250]; } ~MyClass() { delete[] MyMember; } }; And it could be done like this: class MyClass { char MyMember[250]; }; How does a class gets allocated on heap, like if i do MyClass * Mine = new MyClass(); Does th...

copying program arguments to a whitespace separated std::string

I have a Visual Studio 2008 C++ application where I would like to copy all of program arguments in to a string separated by a whitespace " ". i.e., if my program is called as foo.exe \Program Files, then my folder string below would contain \Program Files Below is an example of what I'm doing now. I was wondering if there was a shorter ...

Is correct name enough to make it happen?

Guys, I've just dipped in to limits.h by MS. I tried to check what's the return type for max() fnc and to my surprise I see something like this: // TEMPLATE CLASS numeric_limits template<class _Ty> class numeric_limits : public _Num_base { // numeric limits for arbitrary type _Ty (say little or nothing) public: sta...

Why aren't unsigned OpenMP index variables allowed?

I have a loop in my C++/OpenMP code that looks like this: #pragma omp parallel for for(unsigned int i=0; i<count; i++) { // do stuff } When I compile it (with Visual Studio 2005) I get the following error: error C3016: 'i' : index variable in OpenMP 'for' statement must have signed integral type I understand that the error occur...

Using std::ifstream to load in an array of struct data type into a std::vector

I am working on a bitmap loader in C++ and when moving from the C style array to the std::vector I have run into an usual problem of which Google does not seem to have the answer. 8 Bit and 4 bit, bitmaps contain a colour palette. The colour palette has blue, green, red and reserved components each 1 byte in size. // Colour palette ...

Output integral to ostringstream as binary?

I just realized that one can use bitset to output binary data to a stream based on the (fixed) size of the bitset. What's the least-extra-syntax way to output binary data to a stream using integrals? To show what I mean, here's a program and its output. I'd like the second line of output from this program to be identical to the first li...

Vehicle 2 Vehicle Communication Questions

I have a rare opportunity to meet the man in charge of implementing vehicle 2 vehicle communication for the US Department of Transportation with 2 others in a few hours. Do YOU have any questions for him? I know this is a little outside the normal, but this is a 'reverse' thread and I felt he has some great knowledge on the subject t...

How to write curiously recurring templates with more than 2 layers of inheritance?

All the material I've read on Curiously Recurring Template Pattern seems to one layer of inheritance, ie Base and Derived : Base<Derived>. What if I want to take it one step further? #include <iostream> using std::cout; template<typename LowestDerivedClass> class A { public: LowestDerivedClass& get() { return *static_cast<LowestD...

Calculate the Power Or Number Of Routing Signal

If i change place of Laptop from p1 to p2 , i need function in C++ or Java to calculate the amount or number or power of signals came from router. This function will help me to find the different in (amount Or number Or power) between two position , THANKS. ( Note : i am so sorry about first questions , because i have bad english , and...

How would one call std::forward on all arguments in a variadic function?

I was just writing a generic object factory and using the boost preprocessor meta-library to make a variadic template (using 2010 and it doesn't support them). My function uses rval references and std::forward to do perfect forwarding and it got me thinking...when C++0X comes out and I had a standard compiler I would do this with real v...

C++ class derivation and superconstructor confusion

Hey, in a tutorial C++ code, I found this particular piece of confusion: PlasmaTutorial1::PlasmaTutorial1(QObject *parent, const QVariantList &args) : Plasma::Applet(parent, args), // <- Okay, Plasma = namespace, Applet = class m_svg(this), // <- A member function of class "Applet"? m_icon("document") ...

Specialization of template class for a given templated class

I have a templated class Matrix. I want to write a specialization for complex numbers. How can I do that ? I suspect this won't work : template <typename T> class Matrix { ... } template <typename T2> class Matrix<std::complex<T2> > { ... } But what will ? ...

Repaint window problems

#include "stdafx.h" // Mario Headers #include "GameMain.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name // Mario glo...