Tag Archives: c++

(C++) memory leak detection of static class variables

vc crtdbg detect the memory leaks of static variables by mistake

Posted in C++ | Also tagged , , | 1 Comment

(C++) Reliably Checking Windows Bitness (32-bit or 64-bit)

See on the source (url)

Posted in C++ | Also tagged , , , , , | Leave a comment

Closest pair of points problem in C++

Given n points, find two points with the smallest distance to each other. The examples listed below demonstrate two algorithms in C++ to tackle this problem. One algorithm simply checks every combination of points, also known as a brute force approach. The other one is an efficient algorithm which uses a divide and conquer approach.  The [...]

Posted in C++ | Also tagged , , , , , , , , , | 2 Comments

Matrix multiplication in C++

Matrices can be used to perform transformations. For example, in 2D and 3D space. Transformations include, but are not limited to, rotating, scaling and translating. Transformations can be combined by multiplying the matrices with each other. For example, you might want to: scale an object with a factor of 2 rotate it 45 degrees around the [...]

Posted in C++ | Also tagged , , , , , , , , , , , , , | 2 Comments

Double buffering with a back buffer in VC++

A common problem when drawing with GDI in VC++ is that the screen might flicker when you’re doing a lot of drawing. This problem can be overcome by drawing on a so called back buffer. The back buffer is then drawn at once. I’ve created a Win32 project in VC++ to demonstrate this. The first [...]

Posted in C++ | Also tagged , , , , , , , , , , , | Leave a comment

Distance between 2D and 3D vectors in C++

This example extends the Vector2 and Vector3 classes from the 2D and 3D vector normalization and angle calculation in C++ example. The formulas for distance calculation in 2D and 3D are listed below.

Posted in C++ | Also tagged , , , , , , , | Leave a comment

2D and 3D vector normalization and angle calculation in C++

Normalizing a vector can derive the direction of the vector in 2D or 3D space. A normalized vector is also known as a unit vector. We’re going to normalize and calculate the angles of a 2D vector at position (5,5) and a 3D vector at position (5,5,5). This can come in very handy when, for [...]

Posted in C++ | Also tagged , , , , , , , , , , , , , , , , , , , , , , , | 2 Comments

Classes in C++

C++ can be used for object-oriented programming. This example shows you how to define a class and a header file belonging to it.

Posted in C++ | Also tagged , , , , , , , | Leave a comment

Pointers in C++

Pointers in C++ are used to point to a location in memory. The memory address is stored in the pointer. Suppose we have a temperature variable of type float and a pointer which points to a variable of type float.

Posted in C++ | Also tagged , , , , | Leave a comment