c++ - invalid covariant return type error -


this question has answer here:

i getting below error on overriding base class function in derived class.

./inc/rbtree.h:16:18: error: invalid covariant return type ‘virtual rbnode* rbtree::get_root()’ ./inc/tree.h:25:24: error:   overriding ‘virtual node* tree::get_root()’ 

rbtree.h

class rbnode;  class rbtree: public tree {     protected:     public:         rbtree();         rbnode *root;         rbnode * get_root();         void insert_into_tree();         //void delete_from_tree(); }; 

and tree.h below

class node;  class tree {     protected:         node * root;         list<int> treedata;     public:         tree();         /* gives error */         virtual node * get_root();         void set_root(node *root_node);         void insert_into_tree();         void delete_from_tree();         void print_tree(); }; 

more info: rbnode derived node. , read article , says alright override base class function return derived type instace.

i searched on well, questions regarding didn't much. why failing if allowed in c++.

it appears forward-declaring rbnode. when compiler sees rbtree, doesn't yet know rbnode node.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -