Skip to content

Instantly share code, notes, and snippets.

View drodil's full-sized avatar
💣

Heikki Hellgren drodil

💣
View GitHub Profile
Class inheritance BaseClass visibility Inheriting class visibility
public public public
protected protected
private none
protected public protected
protected protected
private none
private public private
#include <iostream>
#include <string>
class Singleton {
public:
// Returns a reference to static instance of this class
static Singleton& instance() {
static Singleton instance;
return instance;
}
#include <iostream>
#include <string>
#include <map>
class Mapleton {
public:
// Returns a reference to static instance of this class
// based on provided string identifier
static Mapleton& instance(const std::string& id) {
static std::map<std::string, Mapleton> instances;
find impl/ -iname *.hpp -o -iname *.cpp -o -iname *.h | xargs clang-format -i -style=file
#include <iostream>
class HiMyNameIs {
public:
void SlimShady() { std::cout << "Hi! My name is (what?)" << std::endl; }
};
void HiMyNameIs() {
std::cout << "My name is who?" << std::endl;
}
/// object_pool.hpp
#include <functional>
#include <iostream>
#include <memory>
#include <stack>
#include <tuple>
// Base class for all poolable objects
class PoolableObject {
#include <iostream>
#include <stdexcept>
class Note {
public:
int PublicField;
std::string GetPrivateField() {
return privateField;
}
void SetPrivateField(const std::string& field) {
package main
import (
"fmt"
"os"
"errors"
)
func NewNote(field string) (Note, error) {
inst := Note{}
@drodil
drodil / gist:bce67cddf2a758e686cf68768c647cb4
Last active October 18, 2021 09:02
Optional.orElse failure
class Session {
public String getCustomerName() {
// Some checks and throws exception if session not started
throw new SessionNotStartedException();
}
public static Session getCurrentSession() {
return new Session();
}
}
class Session {
public String getCustomerName() {
// Some checks and throws exception if session not started
throw new SessionNotStartedException();
}
public static Session getCurrentSession() {
return new Session();
}
}