c++

About MySQL++, GPL and LGPL

Hi all. MySQL++ is licensed though LGPL, that means that I could release an executable dynamically linked against it without worrying about the source code not being GPL. But, MySQL++ DOES link against libmysqlclient{_r}.{a,so} ( http://tangentsoft.net/mysql++/#linkerrors ) which is GPLed. As seen as then MySQL++ is technically just a '...

When is C++ covariance the best solution?

This question was asked here a few hours ago and made me realise that I have never actually used covariant return types in my own code. For those not sure what covariance is, it's allowing the return type of (typically) virtual functions to differ provided the types are part of the same inheritance hierarchy. For example: struct A { ...

Usage guidelines: shared versus normal pointers

Is there a rigid guideline as to when one should preferably use boost::shared_ptr over normal pointer(T*) and vice-versa? ...

How can I keep track of (enumerate) all classes that implement an interface

I have a situation where I have an interface that defines how a certain class behaves in order to fill a certain role in my program, but at this point in time I'm not 100% sure how many classes I will write to fill that role. However, at the same time, I know that I want the user to be able to select, from a GUI combo/list box, which con...

C++ unit testing with Microsoft MFC

Hey all, I'm trying to convince my organization to start running unit tests on our C++ code. This is a two-part question: Any tips on convincing my employer that unit testing saves money in the long run? (They have a hard time justifying the immediate expenses.) I'm not familiar with any C++ testing frameworks that integrate well with...

Automatic break when contents of a memory location changes or is read

The old DEC Tru64 UNIX debugger had a feature (called "watchpoints to monitor variables") that would watch a memory location (or range of addresses) for read or write activity and when it detected such activity would break the program so you could investigate why. See for details: http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V...

example for using streamhtmlparser

Can anyone give me an example on how to use http://code.google.com/p/streamhtmlparser to parse out all the A tag href's from an html document? (either C++ code or python code is ok, but I would prefer an example using the python bindings) I can see how it works in the python tests, but they expect special tokens already in the html at w...

What's the simplest and most efficient data structure for building acyclic dependencies?

I'm trying to build a sequence that determines the order to destroy objects. We can assume there are no cycles. If an object A uses an object B during its (A's) construction, then object B should still be available during object A's destruction. Thus the desired order of destruction is A, B. If another object C uses object B during its (...

Is there a generally accepted idiom for indicating C++ code can throw exceptions?

I have seen problems when using C++ code that, unexpectedly to the caller, throws an exception. It's not always possible or practical to read every line of a module that you are using to see if it throws exceptions and if so, what type of exception. Are there established idioms or "best practices" that exist for dealing with this proble...

Converting old and new local times to UTC under Windows XP/Server 2003

My application converts past and present dates from local time to UTC. I need to ensure I will honor any future DST updates to Windows while still correctly handling past dates. The application is written in C++ and is running on Server 2003. Options I've researched: gmtime() and localtime() are not always correct for past dates bec...

C++ shared library shows internal symbols

I have built a shared library (.dll, .so) with VC++2008 and GCC. The problem is that inside both libs it shows the names of private symbols (classes, functions) and they weren't exported. I don't want my app to display the name of classes/functions that weren't exported. Is any way i can do that? In GCC i did: Compiled with -fvisibilit...

A generic method to set the length of a dynamic array of arbitrary type in c++

I am doing a project converting some Pascal (Delphi) code to C++ and would like to write a function that is roughly equivalent to the Pascal "SetLength" method. This takes a reference to a dynamic array, as well as a length and allocates the memory and returns the reference. In C++ I was thinking of something along the lines of void* ...

Code crash when storing objects in `std::map`

typedef std::map<int, MyObject*> MyMap; MyMap* myMap = new MyMap; // ... myMap->insert( MyMap::value_type( 0, objectOfType_MyObject ) ); Why does my code crash with a stack trace going down to std::less<int>::operator() ? I understand that if I use a custom key class that I must provide a comparator, but this is an int. I'v...

c++ preprocessor macro expansion to another preprocessor directive

Hi, Initially I thought I needed this, but I eventually avoided it. However, my curiosity (and appetite for knowledge, hum) make me ask: Can a preprocessor macro, for instance in #include "MyClass.h" INSTANTIATE_FOO_TEMPLATE_CLASS(MyClass) expand to another include, like in #include "MyClass.h" #include "FooTemplate.h" template c...

ActiveMQ c++ tutorial

Does anyone recommend a good tutorial on JMS with c++ and ActiveMQ? ...

How to encrypt and decrypt a file with Qt/C++?

I want to create a program, which can encrypt and decrypt a complete file with an individual password. Is there any way to manage this in Qt and/or C++ and how? ...

Read binary C float in Actionscript 3?

I have binary C/C++ data types (e.g. in memory version of a C float) which I need to read into Actionscript 3 and would prefer not to code this from scratch. Anyone know of any libraries, sample code, pseudo code to help with this? For example: C/C++ app: float f = 1.1; SaveFloatToFile(f, 'myfile.bin'); Actionscript 3 app: var ba:...

Access Motherboard information without using WMI

I need to access motheroard identification (serial, manufacture, etc) in my application on multiple processes. I have been able to successfully query this using WMI, but I'm looking for an alternative. If you care to know situation: I have some application behavior that is different depending on the hardware configuration, or if a par...

Reading std::string from binary file

I have a couple of functions I created a while ago for reading and writing std::strings to a FILE* opened for reading in binary mode. They have worked fine before (and WriteString() still works) but ReadString() keeps giving me memory corruption errors at run-time. The strings are stored by writing their size as an unsigned int before th...

Which STL container should I use for a FIFO?

Which STL container would fit my needs best? I basically have a 10 elements wide container in which I continually push_back new elements while pop_front ing the oldest element (about a million time). I am currently using a std::deque for the task but was wondering if a std::list would be more efficient since I wouldn't need to realloca...