template <class E, class K>
class SortedChain {
public:
SortedChain() { first = 0; }
~SortedChain();
bool IsEmpty() { return (first == 0); }
//int Length() const;
//bool Search (const K& k, const E& e);
SortedChain<E, K>& Delete(const K& k, E& e);
SortedChain<E, K>& Insert(const K& k, const E& e);
***SortedChain<E, K>& Merge(SortedChain<E, K> & S2 const);***
void Output() const;
private:
Node<E, K> *first;
};
sortedchain merge给出了以下错误:
感谢任何帮助
答案 0 :(得分:0)
const
的展示位置只有错误
如果你想让参数引用常量,那么使用下面的
template <class E, class K>
class SortedChain {
public:
SortedChain() { first = 0; }
~SortedChain();
bool IsEmpty() { return (first == 0); }
//int Length() const;
//bool Search (const K& k, const E& e);
SortedChain<E, K>& Delete(const K& k, E& e);
SortedChain<E, K>& Insert(const K& k, const E& e);
SortedChain<E, K>& Merge(const SortedChain<E, K> & S2);// change this
void Output() const;
private:
Node<E, K> *first;
};
你可以让这个函数为类对象保持不变,然后使用这个
template <class E, class K>
class SortedChain {
public:
SortedChain() { first = 0; }
~SortedChain();
bool IsEmpty() { return (first == 0); }
//int Length() const;
//bool Search (const K& k, const E& e);
SortedChain<E, K>& Delete(const K& k, E& e);
SortedChain<E, K>& Insert(const K& k, const E& e);
SortedChain<E, K>& Merge(SortedChain<E, K> & S2) const;// change this
void Output() const;
private:
Node<E, K> *first;
};