《Effective C++》0 导读 Introduction

整理每个章节的代码与重点,也会整理自己的心得。

每天进步一点点

0 导读

#include <iostream>

using namespace std;

#if 0
//所谓声明式(declaration) 是告诉编译器某个东西的名称 和 类型(type),但是略去细节
extern int x; 						//object

std::size_t numDigits(int number);  //function
//numDigits的签名是 std::size_t (int) 一个函数的签名是参数和返回值

class Widget; 						// class

template<typename T>				//template
class GraphNode;
#endif

#if 0
//定义式的任务是提供编译器一些声明式锁一楼的细节。对对象而言,定义式是编译器为此对象拨发内存的地点。
int x;

//返回数字的位数
std::size_t numDigits(int number)
{
	std::size_t digitsSoFar = 1;
	while((number /= 10) !=0)
		++digitsSoFar;
	return digitsSoFar;
}

class Widget
{
public:
	Widget();
	~Widget();
};

template<typename T>
class GraphNode
{
public:
	GraphNode();
	~GraphNode();
};
#endif

#if 0
//关于 explicit 阻止隐式转换
class A
{
public:
	A();
};

class B
{
public:
	explicit B(int x = 0, bool b = true);
};

class C
{
public:
	explicit C(int x);
};

void doSomething(B bObject)
{
	cout<<"doSomething"<<endl;
}

int main(int argc, char *argv[])
{
	B bObj1;
	doSomething(bObj1);

	B bObj2(28);

	doSomething(28);
	doSomething(B(28));

	return 0;
}
#endif

class Widget
{
public:
	Widget();
	Widget(const Widget & rhs);
	Widget & operator= (const Widget & rhs);
};

int main(int argc, char ** argv)
{
	Widget w1;
	Widget w2(w1);
    w1 = w2;
    Widget w3 = w2;
	return 0; 
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值