c++

Using C++ hex and cin

If you have the following code: cout << hex << 10; The output is 'a', which means the decimal 10 is converted into its hexadecimal value. However, in the code below... int n; cin >> hex >> n; cout << n << endl; When input is 12, the output becomes 18. Can anyone explain the details of the conversion? How did it became a decimal va...

STLport crash (race condition, Darwin only?)

When I run STLport on Darwin I get a strange crash. (Haven't seen it anywhere else than on Mac, but exactly same thing crash on both i686 and PowerPC.) This is what it looks like in gdb: Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: 13 at address: 0x0000000000000000 [Switching to process 21097] 0x000000010120f...

ComCtl32.dll Version 6 with Qt

I'm trying to implement a balloon tip. By following the instructions on this page: http://msdn.microsoft.com/en-us/library/bb760252%28VS.85%29.aspx I managed to implement the balloon, but the balloon is not using the appropriate theme under Win7. I read somewhere else that for the balloon to use the right visual style, ComCtl32.dll Ver...

Exception specification when overriding a virtual function

Consider the following code: class A { public: virtual void f() throw ( int ) { } }; class B: public A { public: void f() throw ( int, double ) { } }; When compiled, it says that derived class B has a looser throw specifier compared to A. What is the importance of this? If we try to exchange their exception specification, su...

In what state should my overridden >> operator leave my object when the input stream contains invalid data?

Say I have overridden the >> operator for a class like below: friend istream& operator>>(istream& in, MyObject& obj) { ... if (in.fail()) // What do I do here? Should obj be returned unmodified? ... } and say that the input stream is in a fail state because the data there means that I cannot get a valid MyObject o...

Basic questions about RAII, STL pop, and PIMPL

While reading proggit today, I came upon this comment in a post about how the top places in the Google Ai challenge were taken by C++. User reventlov declares The biggest problem I have with C++ is that it's waaay too easy to think that you're a "C++ programmer" without really understanding all the things you need to understand to us...

c++ recursive mpl::equal problem?

i need an mpl::equal like procedure that supports recursion on types. namespace mpl = boost::mpl; BOOST_MPL_ASSERT(( mpl::equal< mpl::vector<int, char>, typename mpl::push_back<mpl::vector<int>, char>::type > )); // OK the above compiles fine, however if i use it in mpl::transform or mpl::fold, visual studio 2010 rc1 complains. ...

Opening multiple files in C++

I have this code to open multiple files one at a time that is given at the command line, and then if it cannot open one of the files, it closes all the files and exits. /* Opens an array of files and returns a pointer to the first * element (the first file). */ ifstream *OpenFiles(char * const fileNames[], size_t count) { /* If...

How to speed up my sparse matrix solver?

I'm writing a sparse matrix solver using the Gauss-Seidel method. By profiling, I've determined that about half of my program's time is spent inside the solver. The performance-critical part is as follows: size_t ic = d_ny + 1, iw = d_ny, ie = d_ny + 2, is = 1, in = 2 * d_ny + 1; for (size_t y = 1; y < d_ny - 1; ++y) { for (size_t x...

Where is the memory for a local C++ vector allocated?

I noticed that the memory for vector is allocated dynamically. So for a local vector, where does the memory is allocated? f(){ vector<int> vi; } ...

Is Qt 4.6 compiled with Cocoa by default on Snow Leopard?

At work, I was told to configure and build Qt 4.6 with the cocoa flag ./configure -cocoa Instead I just ran configure without any flags on my Mac OS X 10.6 machine. Does that mean I have to reconfigure or is cocoa linked by default in Snow Leopard? Alternatively, how can I check if my Qt build is linked against cocoa? ...

C++ - Load all filename + count the number of files in a current directory + filter file extension

I want to count the number of file in the current directory as well as load all file names in the array. If possible, I want to know how to filter file extension also ...

Need help understanding _set_security_error_handler()

So , I've been reading this article: http://msdn.microsoft.com/en-us/library/aa290051%28VS.71%29.aspx And I would like to define my custom handler.However, I'm not sure I understand the mechanics well.What happens after a call is made to the user-defined function ( e.g. the argument of _set_security_error_handler() ) ? Does the program...

Downcasting non-template base class to templated derived class: is it possible?

Hi! I'm implementing an event system for a game. It uses an event queue, and a data structure to hold all registered event handlers for a given event type. It works fine so far registering handlers, but when it comes to unregistering them (something that will take place when a game object is destroyed, for instance) I'm having a bit of ...

Identifying overloaded operators in Visual Studio (c++)

Is there any way to quickly visually identify overloaded operators in c++ using Visual Studio? One of the big gotchas IMO in c++ is not knowing that the operator you are using is overloaded. Is there something within Visual Studio or some third party tool which will automatically highlight or color-code overloaded operators? ...

QIcon inside combobox

Hello, I want to include a "remove" icon on entries in my QComboBox, but I am having trouble catching the mouse press event. I've tried to catch it on the combobox, and I've tried reimplemting the QIcon class to catch the mousepress there. No dice. Does anybody know how to do this? -D ...

Object Slicing, Is it advantage ?

Object slicing is some thing that object looses some of its attributes or functions when a child class is assigned to base class. Some thing like Class A{ } Class B extends A{ } Class SomeClass{ A a = new A(); B b = new B(); // Some where if might happen like this */ a = b; (Object slicing happens) } Do we say Object slicing is ...

How do I get missing prototype warnings from g++?

I currently have a project that uses g++ to compile it's code. I'm in the process of cleaning up the code, and I'd like to ensure that all functions have prototypes, to ensure things like const char * are correctly handled. Unfortunately, g++ complains when I try to specify -Wmissing-prototypes: g++ -Wmissing-prototypes -Wall -Werror ...

Visual Studio - can be a breakpoint called from code?

I have a unit test project based on UnitTest++. I usually put a breakpoint to the last line of the code so that the I can inspect the console when one of the tests fails: n = UnitTest::RunAllTests(); if ( n != 0 ) { // place breakpoint here return n; } return n; But I have to reinsert it each time I check-out the c...

On MacOSX, in C++, how to do interprocess communication over shared memory without spin lock?

I have two processes: Producer and Consumer they have a commonly mmaped shared region of memory Memory Now, Producer writes stuff to Memory. Consumer reads stuff from Memory. I would prefer Consumer not to spin wait with Memory is empty. I would prefer Producer not to spin wait when Memory is full. How do I achieve this? ...