user106592
user106592

Reputation: 3

Error:undefined reference to... when calling a member function in another member function

I get an error which I don't understand when constructing a binary search tree:

Here is my declaration of the class:

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);
};

in which I define a function which finds the minimum element in a certain subtree:

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

Then I call this function TREE_MINIMUM when defining BINARY_DELETE function(unfinished yet):

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);
    }
}

However, the compiler sends the error:

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

which I tried several ways to get rid of it but didn't make it. For the function BINARY_MINIMUM, I declared it as well as defined it, I couldn't find what I'm missing, could anybody help me out?

Upvotes: 0

Views: 60

Answers (1)

Rook
Rook

Reputation: 6145

This defines a standalone function:

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

You probably wanted this:

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

Don't forget to decorate your member function definitions with the class they belong to!

Upvotes: 3

Related Questions