c++

How to log exceptional situations in C++?

When writing a function, my implementation very frequently looks like this: Call a subfunction If this subfunction fails to execute (because of an exceptional situation): log this failure and abort the current function Otherwise continue calling other subfunctions, which in turn can fail A crucial part is the logging. Every function ...

virtual derived class of a non-virtual base class

I have a virtual class that has been derived from a non virtual class. But when I c-style cast the derived class to base class, the class is corrupted. I am looking at the member variables using the debugger and the member variables are all corrupted when I do that cast. I see there is a 4 byte discrepency when I do that cast(may be the ...

Template specialization with a templatized type

I want to specialize a class template with the following function: template <typename T> class Foo { public: static int bar(); }; The function has no arguments and shall return a result based on the type of Foo. (In this toy example, we return the number of bytes of the type, but in the actual application we want to return some me...

Recoloring an image based on current theme ?

I want to develop a program which recolors the input image based on the given theme the same way as ms-powerpoint application does. I am giving following link that shows what exactly i want to do. I want to generate images same as images in below link under the Dark Variations and light Variations title based on the current theme. h...

How to smooth a histogram?

Hi, I want to smooth a histogram. Therefore I tried to smooth the internal matrix of cvHistogram. typedef struct CvHistogram { int type; CvArr* bins; float thresh[CV_MAX_DIM][2]; /* for uniform histograms */ float** thresh2; /* for non-uniform histograms */ CvMatND mat; /* embedded matrix header for array his...

Creating a Form In C++

Hello, I'm just starting to use MetroWerks CodeWarrior 1.1 For Mac 68k in a Mac System 7.5.5, but I need to know: How can I create a simple Form with a TextBox on it? Thanks. ...

Removing leading and trailing spaces from a string

How to remove spaces from a string object in C++. For example, how to remove leading and trailing spaces from the below string object. //Original string: " This is a sample string " //Desired string: "This is a sample string" The string class, as far as I know, doesn't provide any methods to remove leading...

C++ HTTP Library

Is there a good open source library in C++ which will allow me to grab the contents of an URL (the response to a POST or a GET, like a web service's response) to a string? ...

Looking for some refactoring advice

I have some code that I had to write to replace a function that was literally used thousands of times. The problem with the function was that return a pointer to a static allocated buffer and was ridiculously problematic. I was finally able to prove that intermittent high load errors were caused by the bad practice. The function I wa...

c++ vector of class object pointers

Hi all, What I am trying to do is essentially create two vectors of objects, where some objects are entered into both lists and some are just entered into one. The first problem I found was that when I used push_back() to add an object into both lists the object was copied so that when I changed it from one list the object did not chang...

x86 and x64 stack frames

What is the difference when the compiler allocates variables on the stack in x86 v x64 architectures? Say I have a function foo(){ int i = 5; i += 4; } how is this allocated on the stack differently in these two architectures? ...

C++ message passing doubts

Hello, I'm writing a piece of sotware that needs objects that exchange messages between each other. The messages have to have the following contents: Peer *srcPeer; const char* msgText; void* payload; int payLoadLen; now, Peer has to be a pointer as I have another class that manages Peers. For the rest I'm doubtful... for example I m...

How to check if a file is a DLL?

Given a file, I want to check if this is a DLL, or a shared object (Linux) or a dylib (Mac OS X), or something different. My main interest is differentiating executable and DLL on Linux and Mac OS X. For windows, the extension should be enough for my problem. I already checked that the magic number technique doesn't work for Linux as ex...

How can I display unicode characters in a linux terminal using C++?

I'm working on a chess game in C++ on a linux environment and I want to display the pieces using unicode characters in a bash terminal. Is there any way to display the symbols using cout? An example that outputs a knight would be nice: ♞ = U+265E. ...

What might cause OpenGL to behave differently under the "Start Debugging" versus "Start without debugging" options?

I have written a 3D-Stereo OpenGL program in C++. I keep track of the position objects in my display should have using timeGetTime after a timeBeginPeriod(1). When I run the program with "Start Debugging" my objects move smoothly across the display (as they should). When I run the program with "Start without debugging" the objects occ...

C++ short-circuiting of booleans

I'm new to c++ and am curious how the compiler handles lazy evaluation of booleans. For example, if(A == 1 || B == 2){...} If A does equal 1, is the B==2 part ever evaluated? ...

Implicit type conversions in expressions int to double

I've been trying to reduce implicit type conversions when I use named constants in my code. For example rather than using const double foo = 5; I would use const double foo = 5.0; so that a type conversion doesn't need to take place. However, in expressions where I do something like this... const double halfFoo = foo / 2; etc. I...

Function template in non-template class

Hi, I'm sure that it is possible but I just can't do it, which is: How can I define function template inside non-template class? I tryied something like this: class Stack_T { private: void* _my_area; static const int _num_of_objects = 10; public: /* Allocates space for objects added to stack */ explicit Stack_T(size_t); /* Puts object o...

C++ overloaded function issue

Why does the compiler not find the base class function signature? Changing foo( a1 ) to B::foo( a1 ) works. Code: class A1 ; class A2 ; class B { public: void foo( A1* a1 ) { a1 = 0 ; } } ; class C : public B { public: void foo( A2* /*a2*/ ) { A1* a1 = 0 ; foo( a1 ) ; } } ; int main() { A2* a2 = 0 ; C c...

Combo box inside of list control? (Unmanaged C++)

I'm using unmanaged C++ and I was wondering if I could embed a combo box inside a column of my List View. I have tried googling for information, however I keep finding C# articles on the subject. It seems like the LVCOLUMN's mask can support text and images but I am not finding anything about controls. Any ideas on the subject would be...