C++ 编程:虚拟析构函数、多重继承与链表的深入解析
1. 虚拟析构函数
在使用动态内存时,完成操作后需使用 delete 释放内存。以 Text 对象为例,其实现如下:
//Text class, for use with the SSDL library
#ifndef TEXT_H
#define TEXT_H
#include "shape.h"
class Text: public Shape
{
public:
Text (const char* txt = "") { copy (txt); }
Text (const Text& other) : Shape (other)
{
copy (other.contents_);
}
Text (int x, int y, const char* txt = "") : Shape(x, y)
{
copy(txt);
}
~Text () override { if (contents_) delete contents_; }
const Text& operator=(const Text& other);
const char* contents () const { return contents_; }
void drawAux () const override
{
SSDL_RenderText (conten
超级会员免费看
订阅专栏 解锁全文
1191

被折叠的 条评论
为什么被折叠?



