Set テンプレートを AVL バランス型二分探索木として実装することに成功しました。現在、コードを短くして読みやすくしようとしています。fix_imbalance_left と fix_imbalance_right を、left_or_right でテンプレート化された fix_imbalance にマージすると、問題が発生しました。私は一歩一歩やり直しましたが、今は fix_imbalance(left_or_right,node) にいて、次のエラーが発生します:
adts/implementations/set.cpp:224:3: error: no matching function for call to ‘Set<int>::rotate(Set<int>::nodeT*&)’
adts/implementations/set.cpp:224:3: note: candidate is:
adts/implementations/set.cpp:70:39: note: template<Set<int>::directionT DIRECTION> void Set::rotate(Set<ElemT>::nodeT*&) [with Set<ElemT>::directionT DIRECTION = L, ElemT = int]
回転(ノード)テンプレートが実装され、マージされ(左+右がテンプレートに)、以前は個別のfix_imbalanceで成功していたことに注意してください。私はすでに試しました: 'this->' と functionname の後に両方のテンプレート引数を別々の <> で指定しましたが、どれも役に立ちませんでした。
私が間違っていることを指摘していただけますか?
より多くのコード:
enum directionT { LEFT=0, RIGHT=1 }; // inside class definition
template <directionT DIRECTION> void rotate(nodeT * & t); // line 70, inside class def
template <typename ElemT>
bool Set<ElemT>::fix_imbalance(directionT direction, nodeT * & node)
{
directionT R = (direction==LEFT) ? RIGHT : LEFT;
...
rotate<R>(node); // line 224
...
}
// this below worked before,
// when fix_imbalance_left and fix_imbalance_right were separate
// there I called rotate<LEFT>(node); and rotate<RIGHT>(node); and it worked
template <typename ElemT>
template <typename Set<ElemT>::directionT L>
void Set<ElemT>::rotate(nodeT * & t)
{ ... }
申し訳ありませんが、これを以前に投稿しませんでした。