C++多继承注意事项

本文讨论了C++中多继承的一些注意事项,特别是关于虚基类派生和二义性问题的解决。在尝试实现基类bsTree的dictionary虚函数时,遇到了编译错误。通过查阅资料和使用域指示符解决了这一问题,强调了在多继承情况下保持封装特性的做法。
摘要由CSDN通过智能技术生成

C++多继承注意事

虚基类派生虚基类

template<class K, class E>
class bsTree : public dictionary<K, E>
{
public:
	virtual void ascend() = 0
};

template<class K, class E>
class dictionary
{
public:
	virtual ~dictionary() {}
	virtual bool empty() const = 0;
	// return true iff dictionary is empty
	virtual int size() const = 0;
	// return number of pairs in dictionary
	virtual pair<const K, E>* find(const K&) const = 0;
	// return pointer to matching pair
	virtual void erase(const K&) = 0;
	// remove matching pair
	virtual void insert(const pair<const K, E>&) = 0;
	// insert a (key, value) pair into the dictionary
};

单继承
//二叉树的数据结构
template <class T>
struct binaryTreeNode
{
	T element;
	binaryTreeNode<T>* leftChild,   // left subtree
		* 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值