c++

C++ unicode question

I'm aware of ICU and small libraries like the utf8 one on code project (forget the exact name) however none of these are exactly what I want. What I really want is something like ICU but wrapped up in a more friendly manner. Specifically: Fully Object Orientated Implementations of the c++ standard streams, or at least something tha...

How would std::ostringstream convert to bool?

I stumbled across this code. std::ostringstream str; /// (some usage) assert( ! str ); What does ostringstream signify when used in a bool context? Is this possibly an incorrect usage that happens to compile and run? ...

Hierarchical Memory allocator library for C++

My application is mostly organised in layers so I found that something like the APR memory pools would be the best way. While reading on SO about C++ placement new posts here & here, and a more generic C allocation question I was thinking about hand-crafting a hierarchical pool allocator as suggested in one post, but in the pure NYI tra...

How can I delete a Win32 desktop with running programs, and terminate those programs?

I have this code: #define _WIN32_WINNT 0x0500 #include <cstdlib> #include <iostream> #include <windows.h> using namespace std; int main(int argc, char *argv[]) { HDESK hOriginalThread; HDESK hOriginalInput; hOriginalThread = GetThreadDesktop(GetCurrentThreadId()); hOriginalInput = OpenInputDesktop(0, FALSE, DESKTOP_SWI...

Perplexing STL bug in Release in Visual Studio.

I have what I'm pretty sure is a bug in the optimizer in Visual studio 2005. The problem is with an STL map. Here's the relevant code: MyMapIterator myIt = m_myMap.find(otherID); if (myIt != m_myMap.end() && myIt->second.userStatus == STATUS_A) { //Prints stuff. No side-effects whatsoever. } else if (myIt != m_myMap.end() && myIt->...

OpenMP parallelization on a recursive function

I'm trying to use parallelization to improve the refresh rate for drawing a 3D scene with heirarchically ordered objects. The scene drawing algorithm first recursively traverses the tree of objects, and from that, builds an ordered array of essential data that is needed to draw the scene. Then it traverses that array multiple times to dr...

Qt: adapting signals / binding arguments to slots?

Is there any way to bind arguments to slots ala boost::bind? Here's a for-instance. I have a window with a tree view, and I want to allow the user to hide a column from a context menu. I end up doing something like: void MyWindow::contextMenuEvent (QContextMenuEvent* event) { m_column = view->columnAt (event->x()); QMenu menu; ...

What determines what is written to a C++ pointer when delete is called?

I have a pointer to a given class. Lets say, for example, the pointer is: 0x24083094 That pointer points to: 0x03ac9184 Which is the virtual function table of my class. That makes sense to me. In windbg, everything looks correct. I delete said pointer. Now at 0x24083094 is: 0x604751f8 But it isn't some random garbage, that ...

c++ Operator overloading "-"

I've done operator overloading to "-" for my class graph. It's use isn't totally intuitive (bad coding-I know) but if I do graph3 = graph2-graph1 then graph 3 is supposed to receive only those vertexes in both graph 2 and graph 1. So, I've written the code and when I run the debugger, the operator- function seems to create a new "grap...

Stripping Down VS 2008 Win32 DLL to one file.

I have a VS generated C++ Win32 DLL project. It has the following files: stdafx.h targetver.h myProject.h dllmain.cpp myProject.cpp stdafx.cpp I can remove targetver.h, and merge dllmain.cpp into myProject.cpp. What more can I do to get the simplest file structure, preferably one file. I need to dynamically emit this code file and b...

Mark class/method obselete or depracated in C++

Is there a way of marking methods/classes in C++ as obselete as I would to in c# as follows: [Obsolete("You shouldn't use this method anymore.")] void foo(){} I use the GNU toolchain/Eclipse CDT if that matters. ...

Cross platform programming

I need to write a small program for the university. The problem is, it has to be in C/C++ under linux, and I've never used linux, I anticipate having a lot of problems with the IDE, compilation, and all that. Is it possible to code it under windows and then "copy/paste" the code and compile it under linux? What are limitations I should ...

What are some techniques for migrating a large MFC application to WPF/.NET?

I am currently working on a very large legacy MFC MDI application. It has a large number of UI elements - dockable toolbars, custom tree controls, context menus, etc. It is an image processing application so the main views render themselves using DirectX and OpenGL. The product is about 10 years old and one of the priorities here is t...

How do you determine the length of an unsigned char*?

How do you determine the length of an unsigned char*? ...

Forward declare a class's public typedef in c++

I'm trying to simplify a bunch of header file "include spaghetti" by using forward declarations and moving #includes into the implementation file. However, I keep coming upon the following scenario: //Foo.h #include "Bar.h" class Foo { public: void someMethod(Bar::someType_t &val); }; //Bar.h . . . class Bar { public: typedef std...

Why all java methods are implicitly overridable?

In C++, I have to explicitly specify 'virtual' keyword to make a member function 'overridable', as there involves an overhead of creating virtual tables and vpointers, when a member function is made overridable (so every member function is implicitly not overridable for performance reasons). It also allows a member function to be hidde...

Creating Library with backward compatible ABI that uses Boost.

I'm working on certain C++ library (or more framework). I want to make it backward compatible with previous versions preserving not only API compatibility but also ABI (like the great job Qt does). I use lots of functionality of Boost and it seems for me that this makes backward compatibility just impossible, unless I force user to have...

What is the method for optimizing individual functions in a file in GCC 4.1.1?

Various C / C++ compilers have #pragmas to control optimization. For example: CodeWarrior #pragma optimization_level 0 void func_no_opt() { // Some Work - not optimized } #pragma optimization_level 3 void func_full_opt() { // Some Work - optimized } MSVC #pragma optimize("g", off) void func_no_opt() { // Some Work - no...

Error C1047: Object file created with an older compiler than other objects

I have a project that I'm building in C++ in Release mode in Visual Studio 2008 SP1 on Windows 7 and when I build it I keep getting: fatal error C1047: The object or library file '.\Release\foobar.obj' was created with an older compiler than other objects; rebuild old objects and libraries. The error occurs while linking. ...

Problems with Static Initialization

I'm having some weird issues with static initalization. I'm using a code generator to generate structs and serialization code for a message passing system I wrote. In order to have a way of easily allocating a message based on it's message id I have my code generator ouput something similar to the following for each message type: Messag...