错误:在另一个成员函数中调用成员函数时未定义引用....

时间:2014-05-14 15:15:31

标签: c++

我在构造二叉搜索树时遇到了一个我不理解的错误:

这是我对班级的宣言:

class BINARY{
public:
    struct node{
        double key;
        node *parent;
        node *left;
        node *right;
    };
    node *root;
    int count;
    BINARY();
    bool IS_EMPTY();
    int BINARY_SIZE();
    node *SUCCESSOR(node *pointer);
    node *PREDECESSOR(node *pointer);
    node *BINARY_INSERTION(double element);
    double BINARY_DELETE(node *target);
    node *BINARY_SEARCH(double element);
    void INORDER_TREE_WALK(node *pointer);
    node *TREE_MINIMUM(node *pointer);
    node *TREE_MAXIMUM(node *pointer);
    void TRANSPLANT(node *transtree, node *postion);
};

其中我定义了一个函数,该函数在某个子树中找到最小元素:

BINARY::node *TREE_MINIMUM(BINARY::node *pointer)
{
    BINARY::node *index=pointer;
    while(index->left!=NULL)
    index=index->left;
    return index;
}

然后在定义BINARY_DELETE函数(尚未完成)时调用此函数TREE_MINIMUM:

double BINARY::BINARY_DELETE(BINARY::node *target)
{
    if(target->left==NULL) TRANSPLANT(target->right, target);
    else if(target->right==NULL) TRANSPLANT(target->left, target);
    else{
        BINARY::node *pointer;
        pointer=TREE_MINIMUM(target);
    }
}

但是,编译器发送错误:

In function `BINARY::BINARY_DELETE(BINARY::node*)':
binary.cpp:(.text+0x3dc): undefined reference to `BINARY::TREE_MINIMUM(BINARY::node*)'
collect2: error: ld returned 1 exit status

我尝试了几种方法来摆脱它,但没有成功。对于函数BINARY_MINIMUM,我声明它以及定义它,我找不到我错过的,有人可以帮助我吗?

1 个答案:

答案 0 :(得分:3)

这定义了一个独立的功能:

BINARY::node *TREE_MINIMUM(BINARY::node *pointer) { //...

你可能想要这个:

BINARY::node *BINARY::TREE_MINIMUM(BINARY::node *pointer) { //...

不要忘记用他们所属的类来装饰你的成员函数定义!