C++ Puzzle

Some Puzzle when learn c++

1. why we should put typedef at the begining of a class?

1).Because when you decide to use a data member in the class you have to define it first.

2. In what situation we should use typedef?

3为什么要阻止被友元或者成员拷贝,我们声明这些成员但是不定义他们?

有一个例外,我们可以声明但是不定义一个成员函数。一个尝试去使用未定义的函数会导致链接错误,用过声明一个私有的拷贝构造函数,我们可以阻止任何的拷贝一个类类型的行为,用户在任何时候想要进行类拷贝时在编译时 就会被认为是一个错误,在成员函数中或者在友元函数中,进行的拷贝会在链接时发生错误。

好习惯:
如果要阻止拷贝或者拷贝赋值 最好声明为= delete

为什么在deallocate之前要destroy
destroy函数成员调用i相应对象的Destruct函数,如果不调用Destruct函数可能会发生如内存泄漏的问题.

你可能感兴趣的:(C++ Puzzle)