c++

When can you omit the file extension in an #include directive?

I'm playing around with gmock and noticed it contains this line: #include <tuple> I would have expected tuple.h. When is it okay to exclude the extension, and does it give the directive a different meaning? ...

How to create a .bmp in WinCE

I have a camera that returns raw images that can easily be converted to a bitmap that can be saved to a file by the following C# method (that I did not write). From various sources, I have determined that the pictures have 8 bits per pixel, and may or may not be grayscale. private void rawImgToBmp(byte[] imgData, String fname) { ...

Inheritance instead of typedef

C++ is unable to make a template out of a typedef or typedef a templated class. I know if I inherit and make my class a template, it will work. Examples: // Illegal template <class T> typedef MyVectorType vector<T>; //Valid, but advantageous? template <class T> class MyVectorType : public vector<T> { }; Is doing this advantageous s...

Simple option handling using Boost library (C++)

For instance, using the following syntax: -I [file] -A 1 2 3 Question: How to check if a file was specified and additionally if three (integer) values were specified. I understand the following: po::options_descriptions desc("Allowed options"); desc.add_options() How to then use the specified arguments, for instance: if (ar...

Fully thread-safe shared_ptr implementation

Does anybody know of a fully thread-safe shared_ptr implementation? E.g. boost implementation of shared_ptr is thread-safe for the targets (refcounting) and also safe for simultaneous shared_ptr instance reads, but not writes or for read/write. (see Boost docs, examples 3, 4 and 5). Is there a shared_ptr implementation that is fully th...

C++ calling delete on variable allocated on the stack

Ignoring programming style and design, is it "safe" to call delete on a variable allocated on the stack? i.e. int nAmount; delete &nAmount; or class sample { public: sample(); ~sample() { delete &nAmount;} int nAmount; } ...

dynamic cast with interfaces

I have a class with implements 2 interfaces and inherits 1 class. So, generally it looks like this: class T : public A, public IB, public IC { }; There is one point in the code where I have an "IB *", but could really use an "A *". I was hoping that a dynamic cast would like this: IB *b_ptr = new T; // it's really more complicated, b...

Compile old C++ unix application for using in windows

I need to have a windows executable for some code which was written in 1994 for UNIX. I tried to do this from cygwin environment. The C++ standard was changed from this time and the standard libraries too. I tried to use -std= and -traditional-cpp options, but that options didn't helped me at all. I also found that -fno-for-scope and -f...

Commandline arguments not working - Skips over them completely.

Alright, I'm trying to get arguments to work properly with a small test application. My code is below. I'm not too experienced at C++, so I'm not sure why when I launch test with -print (or --print) it automatically states "Not a valid option" and then finishes up. #include <iostream> int main(int argc, char* argv[]) { int option; ...

Why the functions doesn't execute completely?

Hi, When I try to debug the following function segment, the execution brakes (jumps out of the function) at line pCellTower->m_pCellTowerInfo = pCellInfo: RILCELLTOWERINFO* pCellInfo = (RILCELLTOWERINFO*)lpData; CCellTower *pCellTower = (CCellTower*)cbData; if(pCellTower != NULL) { pCellTower->m_pCellTowerInfo = pCellInfo; } (th...

Porting Windows library using Qt to MacOSX, event loops

Hi, I'm inserting a hook in the MFC message loop so that the Qt events are treated, without running ->exec() on qApp (because it's blocking): LRESULT CALLBACK myHookFn(int ncode, WPARAM wparam, LPARAM lparam) { if (qApp) qApp->sendPostedEvents(); return CallNextHookEx(0, ncode, wparam, lparam); } and int argc = 0; new QAppli...

Is there a market amongst programmers for an OID-keyed blob store?

A friend has developed a very amazing blob store and I think it needs to be used, but I'm wondering whether people think such a thing has a market, and if programmers ever get to make these kinds of decisions. It has support for online backups using deltas and is much faster than anything I know of, it's undergone rigorous testing and b...

Retruning a variable sized array of doubles from C++ to C# - a simpler way ?

I have the following C++ method : __declspec(dllexport) void __stdcall getDoubles(int *count, double **values); the method allocates and fills an array of double and sets *count to the size of the array. The only way i managed to get this to work via pinvoke is : [System.Runtime.InteropServices.DllImportAttribute("xx.dll")] public s...

How can I embed unicode string constants in a source file?

Hi all: I'm writing some unit tests which are going to verify our handling of various resources that use other character sets apart from the normal latin alphabet: Cyrilic, Hebrew etc. The problem I have is that I cannot find a way to embed the expectations in the test source file: here's an example of what I'm trying to do... /// //...

destructors: triviality vs implicit definition

As I understand the standard, a trivial destructor is one which is implicitly declared and whose class has only base and non-static members with trivial destructors. Given the recursivity of this definition, it seems to me that the only "recursion-stopping" condition is to find a base or non-static member with a non-implicitly declared d...

What are the major differences between C and C++ and when would you choose one over the other?

For those of you with experience with both, what are the major differences? For a newcomer to either, which would be better to learn? Are there situations where you might choose C but then other situations where you would choose C++? Is it a case of use the best tool for the job or one is significantly better than the other. I know C+...

Questions about COM/ActiveX objects

I have a pretty good grasp on how a "traditional" .dll works, the differences between dynamic and static loading, etc. However, I'm confused about how COM objects work: it is mandatory to register it (with regsvr32)? can I have two versions of a registered COM object lying in the same/different directory? besides beying packaged insid...

Visual Studio 6 VC++ Project version - how do I increment it?

I am making changes to an old program written in VC++6. the project resources include a 'version' set which include the following: Block Header Comments Company Name File Version Product Version Both FileVersion and ProductVersion are at 1.0.0.97 (where the 97 is a build number and increments each time I build the project) My changes a...

c++ mix new/delete between libs?

if i use the new keyword in my lib which is built differently then my main app. when i delete it in my main app with delete is there a chance that i may get a crash/error? ...

Caching policies and techniques for matrices

Hi all, as explained before, I'm currently working on a small linear algebra library to use in a personal project. Matrices are implemented as C++ vectors and element assignment ( a(i,j) = v; ) is delegated to the assignment to the vector's elements. For my project I'll need to solve tons of square equation systems and, in order to do th...