//
archives

C++

This category contains 6 posts

Using Boost Lambda Expression – Performing Iterations on Vector Elements.

1. Introduction. 1.1 When performing iterations and transformations on STL containers, the Boost Lambda Expressions can be a useful alternative to using regular function class objects. 1.2 For those not familiar with the Boost Lambda Library (BLL), please refer to their library web site for full documentation. 1.3 From the next section onwards, 2 code … Continue reading

Storing C++ Objects in a STL Vector Part 3.

1. Introduction. 1.1 In part 2 of this series of articles, we discussed how to use a STL vector to store pointers to objects. 1.2 The purpose of this was to store items in a vector that are linked to base class objects and through this we create the opportunity to downcast base objects to … Continue reading

Storing C++ Objects in a STL Vector Part 2

1. Introduction. 1.1 In part 1, we concluded that given a base class B, a class D derived from B, and a vector V of class B, it is not possible to store an instance of D in V. Any such instance will be constructed as an object of class B before being stored inside … Continue reading

Storing C++ Objects in a STL Vector Part 1

1. Introduction. 1.1 The STL vector is one of the most useful container classes in STL. 1.2 However, given a base class B, a class D derived from B, and a vector V of type B, it is not possible to store instances of D in V. 1.3 As will be shown later on with … Continue reading

C++ Static and Dynamic Casting – Example Use Case – Part 2

1. Introduction. 1.1 In part 1 of this series of articles, I have demonstrated the shortcomings of static casting. 1.2 I reasoned that static casting is more appropriate for up-casting from a derived class to a base class and not the other way around. 1.3 So how does one safely perform a down-cast from a … Continue reading

C++ Static and Dynamic Casting – Example Use Case – Part 1

1. Introduction. 1.1 Consider the following C++ base and derived classes : class Base { public: Base() : x(0) { } int x; void func() { x = 100; cout << “Base func()” << endl; } }; class Derived : public Base { public: Derived() : y(0) { } int y; void func() { y … Continue reading