c++ - How does one use inheritance when we have a template class have template pointer -
Template pointer when there is a template class
We know that the base class pointers are easily generated The class can point to the object. I created another template class and crossed the base and got generated in it. However, I can not do even with an overloaded = operator, then my equal requirement is required.
Please take a look at this because it clearly explains the situation.
#include & lt; Iostream & gt; using namespace std; Class base 1 {public: int a; Virtual Init Reset () {a = 0; Return; }}; Class 1: Public base 1 {public: int b; Int reset () {b = 0; Return b; }}; Template & lt; Class T & gt; Square templateclass {public: t * p; T & amp; Operator = (Template Class & amp; B) {this.p = reinterpret_cast & lt; T & gt; (BP); Return * This; } Zero Reset MySpace () {P-> Reset (); }}; Int main () {// Your code here template class & lt; Base1 & gt; * P = new template class & lt; Base1 & gt; (); TemplateClass & LT; Derived1 & gt; * Q = New template class & lt; Derived1 & gt; (); P = q; P-> ResetMyself (); Return 0; } When I compile my code, I
prog.cpp: in the function "int main" () one: Prog.cpp: 44 : 3: Error: Template Class & lt; Derived1 & gt; * Â ???? Template class & lt; Base1 & gt; * One ???? Assignment in p = q; ^
template class & lt; Derived1 & gt; and the template class & lt; Base 1 & gt; As is the case with int and double you can not specify pointers on another indicator. You can call templateclose & lt; Derived1 & gt; to the TemplateClass & lt; Base1 & gt; / Code> with a custom templated assignment operator: template & lt; Class T & gt; Square templateclass {public: t * p; Template & lt; Square U & gt; TemplateClass & amp; Operator = (combined template class u & gt; amp; b) {p = bp; Return * This; } Zero Reset MySpace () {P-> Reset (); }}; Then you can do something like this ():
templateclose & lt; Base1 & gt; P; TemplateClass & LT; Derived1 & gt; Q; P = q; Note that the signature of your original assignment operator is wrong. Besides, reinterpret_cast is a terrific idea for this one-to-point-derived conversion To make an indicator-to-base, use static_cast does not an artist use the above version and therefore only the underlying conversion (i.e., from derived to Basis] on the base not around the other.
Comments
Post a Comment