Hungarian Notation for C++

Hungarian notation is used in naming variables and data types. It allows a programmer to quickly see what type of data is being used in a section of code. It has the additional benefit of preventing name clashes between variables, types, and the C++ reserved words.

 

Type Specificiers


  • A — Abstract

    Used with classes that have both pure virtual and
    implemented functions.

    class CAMyAbstractClass
    {
    public:
        void MyDefinedFunction () {
            // Do something
        }
    
        virtual void MyVirtualFunction() = 0;
    };
    
  • C — Class

    Used for any class.

    class CMyClass {
        // class definition
    };
    
  • E — Enumeration

    Used for enumerations.

    enum EMyEnumeration {keValue1, keValue2};
    
  • G — Generic

    Used for parameterized classes, structs, etc.

    template 
    class CGMyGenericClass
    {
        // class definition
    };
    
  • I — Interface Class

    Used for class with only pure virtual methods in them.

    class CIMyInterfaceClass
    {
    public:
        virtual void MyVirtualFunction() = 0;
    };
    
  • M — Macro

    Used for preprocessor macros.

    #define MMax(x, y) ((x < y) ? y : x);
    
  • N — Namespace

    Used for namespaces

    namespace NMyNamspace {
        // namespace members
    }
    
  • P — Parameter Type

    Used for template parameter type

    template <typename PMyParam>
    class CGMyGenericClass
    {
        // class definition
    };
    
  • S — Struct

    Used for structs.

    struct SMyStruct {
        // struct definition
    };
    
  • T — Typedef

    Used for types defined by typedef.

    typedef CMyClass TMyTypedefType;
    
  • U — Union

    Used for union types.

    union UMyUnion {
        int miSomeInt;
        double mdSomeDouble;
    };
    

Type Identifiers


  • a — array

    Used for array data

    int iaIntArray[5];
    
  • b — bool

    Used for boolean data

    bool  bBoolean(false);
    
  • c — char

    Used for char data

    char cCharacter = 'a';
    
  • d — double

    Used for double data

    double dMyDouble = 2.4;
    
  • e — enumerated type

    Used for enumerated data

    EMyEnumType eEnumInstance;
    
  • f — float

    Used for float data

    Float fFloat(6.2);
    
  • g — global

    Used for global data

    int giGlobalInt = 0;
    
  • i — int

    Used for int data

    int iInteger = 3;
    
  • k — const

    Used for const data

    const double kdConstDouble = 5.0;
    
  • l — long

    Used for long data

    long lLong = 4;
    
  • m — member

    Used for member data

    class CMyClass
    {
    public:
        int miMemberInteger;
    };
    
  • p — pointer

    Used for pointers

    int* ipIntPtr = 0;
    
  • pfn — function pointer

    Used for function pointers

    void (*pfnPointerToFunction)(int iArg);
    
  • q — unknown programmer-defined type

    Used for unknown type data

    CPoint qMyPoint;
    
  • r — reference

    Used for references

    int& irIntReference = iInteger;
    
  • s — short

    Used for short data

    short sShort = 4;
    
  • t — type

    Used for type data

    class CMyClass {
        static int tiClassInt;
    };
    
  • u — unsigned

    Used for unsinged data

    unsigned int uiUnsignedInt = 10;
    
  • w — wchar_t

    Used for wide character data

    wchar_t wWideChar = L'X';
    
  • x — unspecified parameterized type

    Used for unspecified parameters

    template 
    void MyFunction(PParam xArgument);