c++

Unexpected loss of precision when dividing doubles

I have a function getSlope which takes as parameters 4 doubles and returns another double calculated using this given parameters in the following way: double QSweep::getSlope(double a, double b, double c, double d){ double slope; slope=(d-b)/(c-a); return slope; } The problem is that when calling this function with arguments for examp...

Getting a dump of a process that crashes on startup

On a customer machine (WinXP SP2) to which I have no access, I have a Win32 EXE (unmanaged C++) that crashes on startup. I guess the best way to troubleshoot this is to obtain a (mini-)dump and analyze it later with windbg or similar. Now, I would normally tell the customer to install Debugging Tools for Windows and run cscript adplus....

C++ Builder [C++ Error] sysmac.h(58): E2040 Declaration terminated incorrectly

I want to create a C++ Builder DLL project that doesn't use VCL. But I get this error in sysmac. Does anyone know the possible cause of this error? ...

Bitmask to Array Index

Hello, Is there a simple way to convert a bitmask in to an array index? ie. If i've got an enum a = 0x01, b = 0x02, c = 0x04, d = 0x08, e = 0x10, etc and I want to store releated data in an array, is there a simple way such that i can convert a to 0, b to 1, c to 2. etc? Many thanks ...

several definitions of the same class

Playing around with MSVC++ 2005, I noticed that if the same class is defined several times, the program still happily links, even at the highest warning level. I find it surprising, how comes this is not an error? module_a.cpp: #include <iostream> struct Foo { const char * Bar() { return "MODULE_A"; } }; void TestA() { std::cout << "...

exception handling in constructor’s initializer list

In my project I found a piece of code in which a method was getting called in constructor's initializer list. Test2(Test* pTest):m_pTest(pTest), m_nDuplicateID(pTest->getTestID()) { } I observed that there is a chance that the users of Test2 might pass NULL to the constructor. Since the pointer is used without validation ther...

Returning a 2-dimensional array of doubles from function

I have this class in which at some point I am computing a array of two doubles: double* QSweep::computeIntersection(double m1, double b1, double m2, double b2){ double* v=new double[2]; v[0]= (b2-b1)/(m1-m2); v[1]= (m1*b2-m2*b1)/(m1-m2); return v; } In another function of the class I am using this array to work with its values. Depe...

DCOM server debug

Hi, I'm learning DCOM and I need to debug a class that I have created, how can I do this? ...

C++ Factory method pattern implementation question

I've been looking at the example C++ Factory method pattern in Wikipedia http://en.wikipedia.org/wiki/Factory_method_pattern and have a couple of questions: 1) Since the factory method is static, does that mean the newly created object won't go out of scope and have the destructor method called when the factory method exits? 2) Why re...

Using shared memory under Windows. How to pass different data

I currently try to implement some interprocess communication using the Windows CreateFileMapping mechanism. I know that I need to create a file mapping object with CreateFileMapping first and then create a pointer to the actual data with MapViewOfFile. The example then puts data into the mapfile by using CopyMemory. In my application I ...

Why doesn't this Blitz++ code compile ?

I'm a blitz++ newbie. So far, so good, but I'm a bit mystified why the commented out line in the code below fails to compile with error: conversion from ‘blitz::_bz_tinyMatExpr<blitz::_bz_tinyMatrixMatrixProduct<double, double, 3, 3, 3, 3, 1, 3, 1> >’ to non-scalar type ‘const m33’ requested I'm on Debian/Lenny (g++ 4.3.2, Blitz 0.9...

Is it possible to split a SWIG module for compilation, but rejoin it when linking?

Hi all I hit this issue about two years ago when I first implemented our SWIG bindings. As soon as we exposed a large amount of code we got to the point where SWIG would output C++ files so large the compiler could not handle them. The only way I could get around the issue was to split up the interfaces into multiple modules and to co...

Why is the destructor not called for the returned object from the function?

I was thinking that when a function returns an object on the stack to the calling function, the calling function gets a copy of the original object but the original object's destructor is called as soon as the stack unwinds. But in the following program, the destructor is getting called only once. I expected it to be called twice. #incl...

String Compare not working in Visual C++ 2005

Hi There, If get a gring from the registry and it correctly displays when I place it in a message box. ::MessageBoxW(0, (LPCWSTR)achValue, _T("Found"), MB_YESNO); The value is stored in archValue which is a DWORD. What I want to do is compare it to the following string "2.0.7045.0" but strcmp fails to work for me. Any ideas on how to d...

looking for free c++ cross platform GUI framework

Hello all im looking for cross platform GUI for free for commercial project ( that means i can't give the code ) no GPL and i guess no LGPL what else its leaving me ? wxWidgets ? Thanks ...

Avoid null pointer checks in C++

Use case: class B { int b; public: int getB() { return b; } }; class A { B *b; public: int getB() { if (b ) { //How can I avoid the null check for b here return b->getB(); } } } ...

ATL: I want to create a coclass that I can use as a parameter for a method in my class. Why can't I get this to work?

Hello Everyone, I've created a COM object using ATL. I want to create a new object that can be returned from a method, and passed in as a parameter. I've created the coclass, but I can't figure out how to add a method that will accept it as a parameter. The error I'm getting is MIDL2025: syntax error: expecting a type specification nea...

Relation between word length, character size, integer size and byte

What is the relation between word length, character size, integer size, and byte in C++? ...

I need to have a key with multiple values. What datastructure would you recommend?

I have an string array filled with words from a sentence. words[0] = "the" words[1] = "dog" words[2] = "jumped" words[3] = "over" words[4] = "the" words[5] = "wall." words[6] = "the" words[7] = "cat" words[8] = "fell" words[9] = "off" words[10] = "the" words[10] = "house." etc. (Stupid example, but it works for this) Each word will be ...

How specific to get on design document?

I'm creating a design document for a security subsystem, to be written in C++. I've created a class diagram and sequence diagrams for the major use cases. I've also specified the public attributes, associations and methods for each of the classes. But, I haven't drilled the method definitions down to the C++ level yet. Since I'm new to C...