I decided to make class for AVL tree. I created insertion method in AVL class but I get error from CLion. It says: Invalid use of 'this' outside of a non-static member function. this is my code:
#include <iostream>
using namespace std;
//declaration of the class called AVL
template <typename T>
class AVL{
public:
// declaration of variables
AVL <T> *left = NULL,*right = NULL;
T key;
int size = 0;
int height = 0;
//define the function for insertion of new element in AVL tree
void insert(T value, AVL <T>* ¤t = this, AVL <T>* &root = this){
// if size of AVL tree is 0 then just insert new element and return
if(root->size == 0){
root->size++;
current->key = value;
return;
}
if(current == NULL){
// creation of new node
root->size++;
current = new AVL<T>;
current -> key = value;
return;
}
if(value < current->key){
// go to the left child
current->height--;
insert(value,current->left,root);
}
else{
// go to the right child
current->height++;
insert(value,current->right,root);
}
}
};
int main() {
// creation of the class instance
AVL<long long>X;
}
in the following code fragment:
AVL <T>* ¤t = this
'this' is underlined with red line. Can someone explain me why I get this error.