[c++] Basic ideas and Style Guide

发布时间:2017-1-21 0:12:22 编辑: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语言。


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!

 

上一篇:【心得】关于删除结构体动态数组指定项的正确方法
下一篇:springMvc配置编码过滤器

相关文章

相关评论