Is it possible to make a member of the base class change a type in a derivative if the derivative has a type that has the same name as its type?
To make it easier, you can imagine that rb_tree :: NODE is called rb_tree :: rb_NODE.
struct search_tree { struct NODE { NODE * parent; NODE * left; NODE * right; }; NODE * root; // ΡΡΠ½ΠΊΡΠΈΡ ΠΏΠΎΠΈΡΠΊ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΠΎΠ³ΠΎ ΠΊΠ»ΡΡΠ° // ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅Ρ ΡΠ»Π΅Π½ search_tree::root int max_() { root; return 1; } insert(); find(); delete(); min(); search_tree::search_tree(){root = new NODE;} }; struct rb_tree : public search_tree { // ΠΌΠΎΠΆΠ½ΠΎ ΡΠ°ΠΊΠΆΠ΅ Π½Π°Π·Π²Π°ΡΡ rb_NODE struct NODE : public search_tree::NODE { char color; }; //!! Π²ΠΎΡ Π·Π΄Π΅ΡΡ Π³Π»Π°Π²Π½ΡΠΉ ΡΠΌΡΡΠ». // ΠΏΠΎΠΏΡΡΠΊΠ° ΠΏΡΠΈΡΠ²ΠΎΠΈΡΡ rb_tree::NODE ΡΠΈΠΏ search_tree::NODE // ΠΌΠ΅Π½Ρ ΠΈΠ½ΡΠ΅ΡΠ΅ΡΡΠ΅Ρ, ΡΡΠΎΠ±Ρ ΠΏΡΠΈ ΡΠΎΠ·Π΄Π°Π½ΠΈΠΈ ΠΎΠ±ΡΠ΅ΠΊΡΠ° root ΠΈΠΌΠ΅Π» // ΡΠΈΠΏ rb_tree::NODE int insert() { NODE * node2; node2 = root; } delete(); };
The general essence is this:
1) ΠΊΠ»Π°ΡΡ search_tree ΡΠ΅Π°Π»ΠΈΠ·ΠΎΠ²Π°Π½, ΡΠ°ΠΌ Π΅ΡΡΡ insert find delete max min 2) ΠΊΠ»Π°ΡΡ rb_tree ΠΏΠΎΠ΄ΠΎΠ±Π΅Π½ search_tree ΠΈΠ·ΠΌΠ΅Π½ΡΠ΅ΡΡΡ ΡΠΎΠ»ΡΠΊΠΎ insert delete ΠΠΎ Π² rb_tree ΡΠΈΠΏ NODE Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅ΡΡ ΠΏΠΎΠ»Π΅ color. Π‘ΠΎΠΎΡΠ²Π΅ΡΡΡΠ²Π΅Π½Π½ΠΎ ΠΌΠ΅ΡΠΎΠ΄Ρ rb_tree:: ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΡΡ rb_tree::NODE, Π° ΠΌΠ΅ΡΠΎΠ΄Ρ search_tree:: search_tree::NODE
Of course, the easiest way is to simply add the color field to the NODE type in the search_tree class and delete the rb_tree :: NODE field, which is now done.
But what interests me is the possibility of implementation as in the question.
search_tree
andrb_tree
templates from theTNode
type. - Costantino Rupert