blog icon indicating copy to clipboard operation
blog copied to clipboard

C++ Naming Style

Open qingquan-li opened this issue 2 years ago • 0 comments

1. Common C++ Naming Conventions

https://github.com/cpp-best-practices/cppbestpractices/blob/master/03-Style.md


  • Projects and Files start with upper case (UpperCamelCase / PascalCase):

    MyProject
    
    HelloWorld.cpp
    
  • Types start with upper case (UpperCamelCase / PascalCase):

    MyClass
    
  • Functions and variables start with lower case (lowerCamelCase):

    myMethod()
    
    string userName;
    
  • Constants are all upper case:

    const double PI = 3.14159265358979323;
    const double EULER_NUMBER = 2.71828;
    

2. Google C++ Style Guide

https://google.github.io/styleguide/cppguide.html#Naming

  • File Names

    Filenames should be all lowercase and can include underscores (_) or dashes (-), prefer "_".

    my_useful_class.cpp
    
  • Type Names

    Type names start with a capital letter and have a capital letter for each new word, with no underscores.

    MyExcitingClass
    
  • Variable Names

    The names of variables (including function parameters) and data members are all lowercase, with underscores between words.

    string table_name;
    
  • Function Names

    Ordinarily, functions should start with a capital letter and have a capital letter for each new word.

    DeleteUrl()
    

qingquan-li avatar Jun 03 '22 23:06 qingquan-li