0

I'm having trouble unsing my AVL tree class in one of my programs, I'm not sure how to include my class and use it with existing code, here is the problem:

I have an AVL tree class: AVL_tree.h and AVL_tree.cpp

I also have a main.cpp file

Also functions.cpp and functions.h, where I store some functions used in main.cpp

So, in main() I create an object from my AVL tree class. I want to pass this object along with some other data (which will serve to change the information stored in the tree) to one of the functions from my functions.cpp. And here is where I can't get it to work. I get several errors like these ones:

main.o:main.cpp|| undefined reference to `AVL_Tree::AVL_Tree()'|
main.o:main.cpp|| undefined reference to `process_vector(std::vector<int, std::allocator<int> >, AVL_Tree&)'|

How can I pass the necessary information to my function in order to modify my tree?

Simplified version of my code files:

main.cpp

#include <vector>
#include "functions.h"
#include "AVL_tree.h"
using namespace std;

int main() {
    AVL_Tree tree;
    vector<int> V;

    V.push_back(11);
    V.push_back(4);
    V.push_back(7);

    process_vector(V, tree);

    return 0;
}

functions.h

#ifndef FUNCTIONS_H
#define FUNCTIONS_H

#include<vector>
#include"AVL_tree.h"
using namespace std;

void process_vector(vector<int> V, AVL_Tree &tree);

#endif // FUNCTIONS_H

functions.cpp

#include<vector>
#include"functions.h"
#include"AVL_tree.h"
using namespace std;

void process_vector(vector<int> V, AVL_Tree &tree){
    for(int i=0;i<vector.size();i++){
        key = vector[i]
        tree.AddLeaf(key);
    }
    return;
}

AVL_tree.h

#ifndef AVL_TREE_H
#define AVL_TREE_H

class AVL_Tree{

private:
    struct node{
        int key;
        node* left;
        node* right;
    };

    node* root;
    node* CreateLeaf(int key);
    node* AddLeafPrivate(int key, node* Ptr);
    int HeightPrivate(node* Ptr);
    int BFactorPrivate(node* Ptr);

public:
    AVL_Tree();
    void AddLeaf(int key);
    int Height(int key);
    int BFactor(int key);

};

#endif // TREE
user3787097
  • 181
  • 3
  • 14

0 Answers0