[c++] Basic ideas and Style Guide

发布时间:2017-2-21 11:03:23 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"[c++] Basic ideas and Style Guide ",主要涉及到[c++] Basic ideas and Style Guide 方面的内容,对于[c++] Basic ideas and Style Guide 感兴趣的同学可以参考一下。

[c++] Basic ideas and Style Guide

Get your own compiler: 

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.9
you can then compile using the command:
g++-4.9 -std=c++14 -Wall -Werror -O2 -o helloworld helloworld.cpp

Style Rules:

Macros should never be required in C++.
Variables should be defined close to their use.
Don’t use malloc/realloc, use new (or smart pointers)
Minimise use of void*, pointer arithmetic, union and c-style casts
Minimise the use of C-style arrays and strings, use vector/array (from C++11) and string instead.


C++ Standard Library

For efficiency reasons, STL is not object-oriented:

    • Makes little use of inheritance, and
    • Makes no use of virtual functions


The Standard Template Library (STL) is a part of the C++ standard library, Some others are:


  • The C standard library
  • Language support: <exception>, <ctime>, ...
  • Strings: <string>, <cstring>, ...
  • Numerics: <cmath>, <complex>, ...
  • I/O: <iostream>, <fstream>, <cstdio>, ...
  • Exception classes
  • Smart pointers
  • Classes for internationalisation support


Containers: vector, list, stack, ...
Algorithms: find, sort, copy, ...
Iterators are the glue between the two!


The compilation process:

1. Preprocessing - handles meta-information (e.g., #include)
2. Compiling - translates C++ into machine code objects
3. Linking - merges objects into a single application


Google 开源项目风格指南


路漫漫其修远兮…… 除了坚持,没有捷径。Good luck!