全部博文(47)
分类: C/C++
2006-02-23 21:25:44
找到个Makefile的HOWTO:
今天写了个比较有复杂的Makefile。碰到的问题:
1.makefile中需要对$进行转义时:$$。
2.不要忘了shell在其中的强大功能。
make过后,碰到了编译及连接错误:
1.抽象类(纯虚)析构必须为被vitrual修饰,并实现
2.导致由此派生的子类重载析构
以下是摘自: 很有用。
Summry:
All classes must have a destructor. If one is not specified, then the
compiler will write one for you. If your destructor is pure virtual,
you still have to supply an implementation.
If you don't implement the pure virtual destructor, you will get a
link error.
There are four possible scenarios for base class destructors:
- Non-virtual destructor.
- Virtual (not pure) destructor
- Pure virtual destructor, no implementation
- Pure virtual destructor, with an implementation
The pros and cons of each of the four scenarios are:
Non-virtual destructor: This would, at first, seem to be a bad idea -
if the class is destroyed polymorphically, then the derived class' dtor will
never be called. However, one phrase that popped up several times in the
discussion was "With C++, you don't pay for what you don't need."
Virtual (not pure) destructor: We are all aware of the reasons for this
- if the class is destroyed polymorphically, the derived class dtor will not
be called. This is a no-brainer and no further discussion is required.
(As a side note, several people wrote that they used pure functions to force
all derived classes to implement the functions - the response to which was,
of course, that only the final class has to implement them; intermediate
base classes can leave the pure functions un-implemented.)
Pure-virtual, dtor not implemented: I did not see any discussion on
this scenario, probably because it is not a legal scenario anyway - the
destructor must be implemented or you'll get a runtime error.
Pure-virtual, dtor implemented: "So, what is the point of a pure virtual
destructor?" - the crux of the matter. What this boils down to is, why
allow a dtor to be pure, given that you must implement it?