c++

Having a destructor take different actions depending on whether an exception occurred

I have some code to update a database table that looks like try { db.execute("BEGIN"); // Lots of DELETE and INSERT db.execute("COMMIT"); } catch (DBException&) { db.execute("ROLLBACK"); } I'd like to wrap the transaction logic in an RAII class so I could just write { DBTransaction trans(db); // Lots of DELETE ...

How to properly rewrite ASSERT code to pass /analyze in msvc?

Visual Studio added code analysis (/analyze) for C/C++ in order to help identify bad code. This is quite a nice feature but when you deal with and old project you may be overwhelmed by the number of warnings. Most of the problems are generating because the old code is doing some ASSERT at the beginning of the method or function. I thin...

char pointers & integer pointers (++)

i have two pointers, char *str1; int *str2; if i look at the size of both the pointers lets assume str1=4 bytes str2=4 bytes str1++ will increment by 1 byte but if str2++ will increment 4 byte could anybody tell e the concept behind this? ...

Exposing a C++ API to C#

So what I have is a C++ API contained within a *.dll and I want to use a C# application to call methods within the API. So far I have created a C++ / CLR project that includes the native C++ API and managed to create a "bridge" class that looks a bit like the following: // ManagedBridge.h #include <CoreAPI.h> using namespace __CORE_API...

VS compiling Error 1256 ( integer overflow in internal computation ... ) during inheritance

Hi there, my problem occurs during compiling Irrlicht3D Engine in VS 2008. 1>Error 1256: integer overflow in internal computation due to size or complexity of "irr::IReferenceCounted" I'm currently merging a very old Softwaredriver I have written with the rest of the engine which is much newer. The main Problme is that I have tried to ...

Objective-C++ compiles for iPhone, but not simulator

I have a C++ library I want to add to my iphone project. In one header file I declare @interface a { cppvirtualclass V; } This compiles fine for the iPhone device with Release settings. However it refuses to compile for the Simulator with or without debug info. It give the error error: type 'V' has virtual member functions. Is...

How to get Version of the software?

Hi All, I am working on getting the version of the Software which is installed on the Computer. I have implemented the logic for reading the Uninstall hive of registry, but i have observed that some of the software are not having version entries in the Uninstall hive of the registry. But i want to show the version of those softwares als...

Using undefined type.

//file list.h #include "stdafx.h" namespace st { struct My_List; typedef My_List list; list* create(const char* name); } //file list.cpp #include "stdafx.h" #include "list.h" namespace st { struct My_List { const char* name_; My_List* left_; My_List* right_; My_List(const char* name)...

Linux, how to capture screen, and simulate mouse movements.

Hi All I need to capture screen (as print screen) in the way so I can access pixel color data, to do some image recognition, after that I will need to generate mouse events on the screen such as left click, drag and drop (moving mouse while button is pressed, and then release it). Once its done, image will be deleted. Note: I need to ...

append set to another set

Hi Is there a better way of appending a set to another set than iterating through each element ? i have : set<string> foo ; set<string> bar ; ..... for (set<string>::const_iterator p = foo.begin( );p != foo.end( ); ++p) bar.insert(*p); Is there a more efficient way to do this ? ...

Constructing / destructing QApplication causes QWebView to mess up rendering of HTML

We need to create & destroy instances of QApplication, as we want to use Qt in a plug-in to an existing host application. void multiQT() { int argc = 0; QApplication app(argc, NULL); QWebView view; view.setHtml("<html><head><title>Title</title></head><body><h1>Hello World</h1></body></html>"); view.show(); app....

C question on casting

Can anybody explain me this statement! pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; ...

Lost in this c++ Builder 2010 Stack Trace

Hello i am getting below EAccessViolation Exception in C++ Builder 2010 project. StackTrace is not showing any of my project file in it. How can i find the location of the error ? This application use TIdTCPServer component. Call Stack Information: ---------------------------------------------------------------------------------------...

c++ opengl: how can i combine 2 different projection types for 3d graphics and 2d menus ?

Hi! I would like to use Oblique projection for menus and perspective projection for the 3d-scene. is there a way to combine between this two projections ? In general I'm asking how can I create menus in opengl for my 3d scene. Programming using the c++ language. Thanks! ...

Direct2D window black when not in focus

Hi all, I have a Direct2D window which paints fine when in focus; however, when focus moves to another window (same application or another), the entire window goes black. I pinned the issue down to the use of ID2D1HwndRenderTarget::Clear. This function is vital to my application as without it, painting becomes rather... weird. Is there...

Boost graph libraries: setting edge weight values

I am investigating the use of the boost graph libraries in order to apply them to various network problems I have in mind. In the examples I have been looking at the graph edge values ("weights") are always initialized as integers, such as in these Bellman-Ford and Kruskal algorithms eg: int weights[] = { 1, 1, 2, 7, 3, 1, 1, 1 }; My ...

When using Doxygen for C++ sources a size of font for \subsubsection is larger than for \section and \subsection

I installed Doxygen 1.6.1. I used \section, \subsection and \subsubsection for titles in C++ sources. I surprisingly obtained titles in which \subsubsection have large font size than for \subsection and \section. How can this be fixed? CSS should be used to workaround this or can I fix my doxygen installation to obtain expected common...

std::deque: How do I get an iterator pointing to the element at a specified index?

I have a std::deque, and I want to insert an element at a specified index (I'm aware that std::list would be better at this). The deque::insert() function takes an iterator to specify the location to insert. Given an index, how can I get an iterator pointing to that location, so that I can pass that iterator to insert()? For example: ...

How to wrap a thirdparty library COM class for notifications in a C++ project

A thirdparty vendor has provided a COM interface as an external API to their product, and for sending instructions to it, it's fine with the mechanism of generating class wrappers with visual studio by importing from the dll, then creating instances of the created classes, calling their CreateDispatch(), using the access functions and re...

C++ Formatting like visual studio c# formatting

I like the way Visual studio (2008) format C# code; unfortunately it seems it doesn't behave in the same way when writing C++ code. For example, when I write a code in this way: class Test { public: int x; Test() {this->x=20;} ~Test(){} }; in C# (ok this is C++ but you can understand what I mean), this part: Test() {this...