码迷,mamicode.com
首页 > 编程语言 > 详细

[c++] Basic ideas and Style Guide

时间:2016-11-20 18:21:57      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:iterator   eal   mpi   uid   lang   require   for   isa   line   

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!

 

 

[c++] Basic ideas and Style Guide

标签:iterator   eal   mpi   uid   lang   require   for   isa   line   

原文地址:http://www.cnblogs.com/jesse123/p/6082879.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!