You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After some experiments, a simple question: is 'this' polymorphic only for simple expression "this", and not when it's used as a qualifier in some reference expression, e.g. "this.foo"?
One thing to note, there are two uses of the keyword this. your example above uses an initializer. this will be evaluated once, in the context of the base class A; the type of the expression this.p here is A, and there is no polymorphism here. if you however, gave c the type this, this will be instantiated in the context of the derived class, and you would get the desired polymorphism.
Activity
zhuravlikjb commentedon Nov 2, 2015
After some experiments, a simple question: is 'this' polymorphic only for simple expression "this", and not when it's used as a qualifier in some reference expression, e.g. "this.foo"?
mhegazy commentedon Nov 2, 2015
One thing to note, there are two uses of the keyword
this. your example above uses an initializer. this will be evaluated once, in the context of the base classA; the type of the expressionthis.phere isA, and there is no polymorphism here. if you however, gavecthe typethis, this will be instantiated in the context of the derived class, and you would get the desired polymorphism.zhuravlikjb commentedon Nov 3, 2015
Thanks, now it's more clear how it behaves.