整理每个章节的代码与重点,也会整理自己的心得。
每天进步一点点
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;
}