Why use Include Guard in C++

They are some potential problems that can be cause by #include  directives. Consider the header file:

// RigidBody.h
#include "coreMath.h"
// ---- Rest of RigidBody declartions

// Scene.h
#include "coreMath.h"
#include "RigidBody.h"

Continue reading “Why use Include Guard in C++”

Posted in C++

Virtual destructor in C++

Virtual destructors are useful when you can delete an instance of a derived class through a pointer to base class.

Here is an example when you don’t use virtual destructors.

class Base
     Base() {cout << "Base Constructor called";}
     // Base destructor is not virtual.
     ~Base() {cout << "Base Destructor called";}

class Derived :public Base
       Derived() {cout << "Derived Constructor called";}
       ~Derived() {cout << "Derived Destructor called";}

void main()
    Base *pBase = new Derived();

    delete pBase;    // Here is the problem.

Continue reading “Virtual destructor in C++”

Posted in C++

C++ Operator Overloading

The type of operator overloading that has some potential performance implications is one that returns an object of the type it operated on, usually binary operators. For example, operator+() is one of those operators. Consider the following code:

Vector3 velocity = oldVelocity + frameIncrement;
Vector3 propulsion = ComputePropulsion();
Vector3 finalVelocity = velocity + propulsion;

Continue reading “C++ Operator Overloading”

Using IMGUI in my Physics Engine.

I just recently implemented ImGui into my physics engine. Working on my physics engine is really fun and challenging, i have a lot more to add and learn to make this a polished programming product. Implementing a Graphical User interface was brought on by looking at the behind the scenes footage of Last Of US by Naughty Dog Inc. They had really simple GUI but it was highly useful to both programmers and game designers. They were able to configure options while Continue reading “Using IMGUI in my Physics Engine.”