Archiv der Kategorie: C++

Prefer non-member functions

In C++ you can write a function as member function of a class or as non-member function outside of classes. But which of this both software designs is applicable? Which one do you should prefer? The answer is easy: It … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

Returning handles to private members makes them public

Some key features of object-oriented programming can be brunch together to something I want to call the “black box idea”. An object is a black box offering a public interface. All internal implementations, like state management, data control and resource … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

Define a variable inside or outside of a loop

If you implement something you will write a lot of loops. Within the loops you will often use variables. This is a very common issue but it isn’t that easy like it looks in the first moment. Because you have … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

Slicing problem

By default C++ will pass parameters by value. Therefore when you pass an object to a method a copy of this object will be created. Other languages, for example C# will pass parameters by implicit references. If you work with … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

Manage resources by using smart pointer RAII objects

A common way to create objects is by using a factory method or an abstract factory. Such a factory will normally create and return the object and handover the responsibility over the object to the client. Therefore the client has … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

Virtual Destructor

You may have heard the advice that a destructor should be declared as virtual in case you use the class as a base class. Within this article I want to show the technical background behind this advice and want to … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

Virtual functions in ctor and dtor

During construction and destruction of an object you are able to call virtual functions. But you should not do this. That’s because it is a source for errors as the behavior of the application may be differ from your expectations … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen