Skip to content

Instantly share code, notes, and snippets.

@dpasca
Last active January 13, 2019 18:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dpasca/5243278 to your computer and use it in GitHub Desktop.
Save dpasca/5243278 to your computer and use it in GitHub Desktop.
// "const auto" is just too common not to have an alias
#define c_auto const auto
class Type; // forward declaration if possible
//==================================================================
class ClassName
{
size_t mMember = 0; // 'm' prefix for member variable
U8 *mpPointer {}; // 'mp' prefix for member pointer
uptr<Type> moUniqueObj; // 'mo' prefix for unique_ptr (Owned)
sptr<Type> msSharedObj; // 'ms' prefix for shared_ptr
public:
// Dedicated 'Params' structure for classes with many parameters,
// especially if they need to be retained
struct Params
{
int param1 = 0;
float param2 = 0;
// ...
};
private:
const Params mPar; // keeps a copy of the ctor params (often useful)
public:
ClassName( const Params &par ) : mPar(par) {}
~ClassName(); // destructor usually necessary only
// to use unique_ptr + forward declaration
// public method with Uppercase initial
void PublicMethod( int yoyo );
private:
// private method with lowercase initial
void privateMethod();
};
//==================================================================
// initial for local (static) function is lowercase
static void localFunction( int oneParam, int anotherParam )
{
}
//==================================================================
// initial for global function is Uppercase
void GlobalFunction(
// multi-line param list when more than 3-4 params
int oneParam,
int anotherParam,
int thirdParam,
size_t fourthParam )
{
// left value and right value are sometimes aligned with virtual tabs
// (never tab chars)
c_auto dude = oneParam;
c_auto longerDude = anotherParam;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment