It's not all that hard to implement a finite-state machine, unless it's very large, and you have to worry about multithreading, and ...

A common design technique in the repertoire of most programmers is the venerable state machine. Designers use this programming construct to break complex problems into manageable states and state transitions. There are innumerable Read More →

Simple Sorting Challenge
Challenge Description:
Write a program which sorts numbers.
Input sample:
Your program should accept as its first argument a path to a filename. Input example is the following

70.920 -38.797 14.354 99.323 90.374 7.581
-37.507 -3.263 40.079 27.999 65.213 -55.552

Output sample:
Print sorted numbers in the following way. Please note, that you need to print the numbers till Read More →

FakeIt is a simple mocking framework for C++. It supports GCC, Clang and MS Visual C++ -
FakeIt is written in C++11 and can be used for testing both C++11 and C++ projects.
Checkout the Quickstart for many more examples!
Download the Latest Release and start using FakeIt now!

Mock objects -

Unit tests follow a simple pattern. Read More →

This class manages socket timeouts by applying the concept of a deadline.Some asynchronous operations are given deadlines by which they must complete. Deadlines are enforced by an "actor" that persists for the lifetime of the client object.
If the deadline actor determines that the deadline has expired, the socket is closed and any outstanding operations are Read More →

Welcome to the Getting Started with MongoDB guide. This guide provides instructions to get you started using MongoDB. The guide covers the following topics:

Introduction to MongoDB as well as instructions to Import Example Dataset;
A brief overview of the C++ MongoDB Driver;
Basic Insert, Find, Update, Remove operations plus Aggregation;
Instructions on creating Indexes to improve query performance.

The Read More →

1.  GCC (GNU Compiler Collection)
1.1  A Brief History and Introduction to GCC
The original GNU C Compiler (GCC) is developed by Richard Stallman, the founder of the GNU Project. Richard Stallman founded the GNU project in 1984 to create a complete Unix-like operating system as free software, to promote freedom and cooperation among computer users and programmers.
GCC, formerly Read More →

The Poisson distribution is a well-known statistical discrete distribution. It expresses the probability of a number of events (or failures, arrivals, occurrences ...) occurring in a fixed period of time, provided these events occur with a known mean rate λ (events/time), and are independent of the time since the last event.
The distribution was discovered by Simé on-Denis Read More →

C++ Copy Constructor passed by value or by reference ?
The parameter in the copy constructor A(A other) is an instance of type A.
When the copy constructor is executed, it calls the copy constructor itself because of the pass-by-value parameter.
Since endless recursive calls cause call stack overflow, a pass-by-value parameter is not allowed in the C++ Read More →

To create the shared (*.so) library, use these steps
Example instructions for compiling
1) g++ -fpic -c CLib.cpp
2) g++ -shared -o CLib.o
3) g++ CLibTest.cpp -o CLibTest -L. -lCLib
C Programming Tutorial in Linux #040 - Dynamic Shared Library
Tell your C++ compiler which instantiations to make while it is compiling your template class's .cpp file.
(If you've already read the previous FAQ, this answer is completely symmetric with that one, so you can probably skip this answer.)
As an example, consider the header file Foo.h which contains the following template class. Note that method Foo<T>::f() Read More →

Google C++ Style Guide

Table of Contents

Header Files

Self-contained Headers
The #define Guard
Forward Declarations
Inline Functions
Function Parameter Ordering
Names and Order of Includes


Nested Classes
Nonmember, Static Member, and Global Functions
Local Variables
Static and Global Variables


Doing Work in Constructors
Explicit Constructors
Copyable and Movable Types
Delegating and Inheriting Constructors
Structs vs. Classes
Multiple Inheritance
Operator Overloading
Access Control
Declaration Order
Write Short Functions

Google-Specific Magic

Ownership and Smart Pointers

Other C++ Features

Reference Arguments
Rvalue References
Function Overloading
Default Read More →

Since a time_t is only required to represent time intervals of ±68 years, and many implementations use a base year of 1970 for representing the current time, there is an inability for many popular C++ implementations to represent dates and times after 2038. This means that a lot of software could break in 2038, if Read More →

This piece of code illustrates how your compiler library handles different settings of the TZ environment variable. It also shows
the problematics arising from time zone conversion localtime/gmtime when daylight saving is currently in effect and the time to be converted would have no daylight time set and vice versa.
In your shell set the environment variable Read More →

You have two objects, and you need to know if their respective classes have a base class/derived class relationship or if they are unrelated.
Use the dynamic_cast operator to attempt to downcast from one type to another. The result tells you about the class’s relationships.
Example presents some code for doing this.
Determining class relationships

#include <iostream>
#include <typeinfo>
using namespace Read More →