Why template classes are defined in header files

Templates need to be instantiated by the compiler before actually compiling them into object code. This instantiation can only be achieved if the template arguments are known. Now imagine a scenario where a template function is declared in a.h, defined in a.cpp and used in b.cpp. When…

Interfaces

When trying to implement a pure abstract class (the equivalent of a Java interface), we should not deal with member visibility. Hence, one possible way is to declare the base class as a struct.…

Being friends

Since the syntax friend class B doesn't declare a member of the class A, it doesn't matter where you write it, class B is a friend of class A. [via @Nawaz]…