• C++随笔


    头文件防卫式声明

    防止头文件重复包含

    方式一:

    #ifndef  __SOMEFILE_H__
    
    #define   __SOMEFILE_H__
    
     ... ... // 声明、定义语句
    
    #endif
    

    方式二:

    pragma once  //防止头文件重复包含
    

    头文件的布局

    #ifndef HEAD_H
    #define HEAD_H
    
    #include <cmath>
    
    //******* forward declarations ******* 
    class ostream;
    class complex;
    
    complex& _doapl(complex& ths, const complex& r);
    //-----------------------------------------------
    
    //*******  class declarations ******* 
    class complex   // class head
    {				// class body 
    	/*
    	……
    	……
    	*/
    	void function();
    };
    //-----------------------------------------------
    
    //******* class definition ******* 
    void complex::function()
    {
    
    }
    //-----------------------------------------------
    #endif
    

    inline(内联)函数

    inline函数仅仅是一个对编译器的建议,所以最后能否真正内联,看编译器的意思。

    构造函数:尽量用列表初始化

    complex (double r = 0, double i = 0) : re (r), im (i){}
    

    等同于

    complex (double r = 0, double i = 0)
    {
    	this.re = r;
    	this.im = i;
    }
    

    参数传递:尽量传引用

  • 相关阅读:
    shell数组(产生不同的随机数)
    统计服务连接状况
    子网掩码与子网划分
    oracle 12g sqlplus安装
    MySQL的备份和还原
    mysql日志
    mysql用户和权限管理
    mysql show
    CentOS Linux解决Device eth0 does not seem to be present
    mysqldump命令详解(转载)
  • 原文地址:https://www.cnblogs.com/gqw-myblogs/p/14412835.html
Copyright © 2020-2023  润新知