C++ Singleton Implementation #pragma once //////////////////////////////////////////////////////////// #include <cassert> #ifdef __APPLE__ #define nullptr NULL #endif //////////////////////////////////////////////////////////// template <typename S> class Singleton { public: Singleton() { assert(!s_instance); s_instance = static_cast<S*>(this); } virtual ~Singleton() { assert(s_instance); s_instance = 0; } static S* Instance() { return s_instance; } private: static S* s_instance; }; template <typename S> S* Singleton<S>::s_instance = […]
Category: Programming Languages
C++ – Why make the constructor Explicit
The compiler is allowed to make one implicit conversion to resolve the parameters to a function. What this means is that the compiler can use constructors callable with a single parameter to convert from one type to another in order to get the right type for a parameter. Here’s an example class with a constructor that can […]
C++ in-class initialization
The two code snippets you posted are not quite equal. class Something { int m_a = 0; }; Here you specify the value with which to initialize, i.e. 0, at compile time. class Something { int m_a; Something(int p_a); }; Something::Something(int p_a):m_a(p_a){ … }; And here you do it at run time (or possibly at run time), with […]
SQL Comments
Single Line Comments Single line comments start with –. Any text between — and the end of the line will be ignored (will not be executed). The following example uses a single-line comment as an explanation: –Select all: SELECT * FROM Customers; The following example uses a single-line comment to ignore the end of a […]
Naming conventions
snake_case SCREAMING_SNAKE_CASE kebab-case camelCase PascalCase
Ruby Style Guide
TODO
Ruby Last line Return
TODO
Ruby Symbols
TODO
Ruby DO END vs { } Curly Braces
TODO