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;
}

在这里插入图片描述

参数传递:尽量传引用

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值