c++

C/C++ function/method decoration

DISCLAIMER: I haven't done C++ for some time... Is it common nowadays to decorate C/C++ function/method declarations in order to improve readability? Crude Example: void some_function(IN int param1, OUT char **param2); with the macros IN and OUT defined with an empty body (i.e. lightweight documentation if you will in this example). ...

Does an ATL COM Object Have a Message Pump?

If you create a new ATL project and add a simple COM object to it (note: an object and not a control) that uses the Apartment threading model, will there be a message pump running under the hood? I want to create a hidden window that is a member of my COM object class but I'm not sure if any messages will actually be delivered to it or ...

Difference between hash_map and unordered_map?

I recently discovered that the implementation of the hash map in c++ will be called unordered_map. When I looked up why they weren't just using hash_map, I discovered that apparently there are compatiblity issues with the implementation of hash_map that unordered_map resolves(http://en.wikipedia.org/wiki/Unordered_map_%28C%2B%2B%29). The...

What caused the mysterious duplicate entry in my stack?

I'm investigating a deadlock bug. I took a core with gcore, and found that one of my functions seems to have called itself - even though it does not make a recursive function call. Here's a fragment of the stack from gdb: Thread 18 (Thread 4035926944 (LWP 23449)): #0 0xffffe410 in __kernel_vsyscall () #1 0x005133de in __lll_mutex_loc...

push_front C++ user implementation

Im tryin to implement a push front method to a C++ double ended queue. The way that i did it was shifting each element of the array. It worked, but my program crashes at the end! In my push front method I seem to be "running past the end of my array", resulting in a heap corruption error, debug assertion, those things.. I havent been ab...

Boost installation -Simplified Build From Source

As mentioned in the docs what do i need to install to run the commands : bootstrap .\bjam The BoostPro Computing folks maintain the Boost installer for Windows, but if I first run the installer and download a minimal build and then run the installer again, the installer doesn't detect that I've already installed Boost already and I ...

Valgrind reports "Invalid free() / delete / delete[]" (C++)

I'm not sure what could be causing this. ==18270== Invalid free() / delete / delete[] ==18270== at 0x400576A: operator delete(void*) (vg_replace_malloc.c:342) ==18270== by 0x80537F7: LCD::LCDControl::~LCDControl() (LCDControl.cpp:23) ==18270== by 0x806C055: main (Main.cpp:22) ==18270== Address 0x59e92c4 is 388 bytes inside a b...

boost lib build configuraton variations

I am new to boost - can you please tell me what are the difference b/w the following variations of the boost lib and which one do I need to link to in which case? libboost_unit_test_framework-vc80-1_35.lib libboost_unit_test_framework-vc80-gd-1_35.lib libboost_unit_test_framework-vc80-mt-1_35.lib libboost_unit_test_framework-vc80-mt-...

How can I have optional default constructor?

This class: template <class T> struct A { A() : t(T()) { } A(const T& t_) : t(t_) { } T t; }; won't compile if T doesn't have default constructor. This one: template <class T> struct A { A(const T& t_) : t(t_) { } T t; }; won't have default constructor even if T has default constructor. I want to have both - If...

Circular Array C++

Hello, The code below is my own implementation a push_front method for my items array. I was wondering if someone could help me figure out how to implement the method so that i am just moving the indexes up or down. I need my items to stay in the array, rather then dumping them into a "front" varaible: stack::stack(int capacity) : item...

Way to link 2 variables in a class in C++

Say I wanted to have one variable in a class always be in some relation to another without changing the "linked" variable explicitly. For example: int foo is always 10 less than int bar. Making it so that if I changed bar, foo would be changed as well. Is there a way to do this? (Integer overflow isn't really possible so don't worry ab...

Why don't STL containers have virtual destructors?

Does anyone know why the STL containers don't have virtual destructors? As far as I can tell, the only benefits are: it reduces the size of an instance by one pointer (to the virtual method table) and it makes destruction and construction a tiny bit faster. The downside is that it's unsafe to subclass the containers in the usua...

C++ : struggle with generic const pointer

I've run into some annoying issues with const-correctness in some templated code, that ultimately boils down to the following observation: for some reason, given an STL-ish Container type T, const typename T::pointer does not actually seem to yeild a constant pointer type, even if T::pointer is equivalent to T::value_type*. The followin...

Difference between pass-by-reference & and * ?

What is the difference between passing-by-reference and using the C pointer notation? void some_function(some_type& param) and void some_function(some_type *param) Thanks ...

QT: Using QPainter on child widgets

I'm having a QT/C++ problem with a simple QWidget program that draws an ellipse inside a child QWidget. The program is composed of: (1) A parent QWidget (2) A child QWidget (used as the drawing surface for an ellipse) (3) A draw QPushButton Here is part of the code (QPushButton Slot and Signal code omitted for simplicity) void Draw::...

Nokia QT 4 for Visual Studio 2005 and Visual Studio 2008

I downloaded the latest open source version of QT4-and its installed in c:\qt\2009.04. I've also downloaded the QT4 Visual Studio add-in 1.1.0. I want to set it up for both Visual Studio 2005 and Visual Studio 2008 . Most of the docs online are for older versions. What steps do I follow? ...

ifstream: how to tell if specified file doesn't exist

I want to open a file for reading. However, in the context of this program, it's OK if the file doesn't exist, I just move on. I want to be able to identify when the error is "file not found" and when the error is otherwise. Otherwise means I need to quit and error. I don't see an obvious way to do this with fstream. I can do this wi...

Deleting a shared pointer (C++)

I have a pointer to a QScriptEngine that I'm passing through the overloaded class constructor of class Evaluator and assigns it to QScriptEngine *engine_ (class Property subclasses Evaluator, and calls this constructor of Evaluator, passing it an already allocated QScriptEngine). The constructor with no arguments creates the new QScriptE...

C state-machine design

I am crafting a small project in mixed C and C++. I am building one small-ish state-machine at the heart of one of my worker thread. I was wondering if you gurus on SO would share your state-machine design techniques. NOTE: I am primarily after tried & tested implementation techniques. UPDATED: Based on all the great input gathered o...

Do shallow copies share pointers? (C++)

I know that if I do something like this: class Obj { public: int* nine; }; Obj Obj1; //Awesome name int eight = 8; Obj1.nine = &eight; Obj Obj2 = Obj1; //Another Awesome name then Obj1's and Obj2's nines will point to the same 8, but will they share the same pointer? I.e.: int Necronine = 9; Obj1.nine = &Necronine; Obj2.nine == ...