Re: Virtual method call from constructor

2023-04-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/4/23 3:08 AM, Chris Katko wrote: Second, could you give me some case examples where this problem occurs? Is the issue if I override refresh in a derived class, and the base class will accidentally use child.refresh()? An example of a problem: ```d class Base { this() {

Re: Virtual method call from constructor

2023-04-05 Thread Johan via Digitalmars-d-learn
On Tuesday, 4 April 2023 at 07:08:52 UTC, Chris Katko wrote: dscanner reports this as a warning: ```D struct foo{ this() { /* some initial setup */ refresh(); } void refresh() { /* setup some more stuff */} // [warn] a virtual call inside a constructor may lead to unexpected results in

Re: Virtual method call from constructor

2023-04-04 Thread Ali Çehreli via Digitalmars-d-learn
On 4/4/23 00:08, Chris Katko wrote: > dscanner reports this as a warning: > > ```D > struct foo{ > this() >{ >/* some initial setup */ >refresh(); >} > void refresh() { /* setup some more stuff */} > // [warn] a virtual call inside a constructor may lead to unexpected > results in

Re: Virtual method call from constructor

2023-04-04 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
> Firstly, are all calls virtual in a struct/class in D? In D structs are always value types without a vtable or inheritance. Classes are always reference types with a vtable, but some of the methods may be final and hence not in vtable. > Second, could you give me some case examples where

Virtual method call from constructor

2023-04-04 Thread Chris Katko via Digitalmars-d-learn
dscanner reports this as a warning: ```D struct foo{ this() { /* some initial setup */ refresh(); } void refresh() { /* setup some more stuff */} // [warn] a virtual call inside a constructor may lead to unexpected results in the derived classes } ``` Firstly, are all calls virtual