Thanks in advance!
The difference is the same as for any other method: virtuals can be
overridden by subclasses.
Peter
> Could somebody please explain to me what exactly the difference
> is between a virtual and a non virtual constructor?
>
> Thanks in advance!
>
>
Virtual constructors (like any virtual method) can be overridden in
descendant classes.
--
Alvin Lee
Virtual constructor is just the same thing as virtual function - you can
override it.
When you create an instance using class ref (and a base class has a virtual
constructor) a proper constructor get called. This wouldn't be possible with
a static one.
Good luck, Serge
--
http://www.cooldev.com/
#CoolControls, CoolMenus and more Cool VCL packs for Delphi development.
#KoolSockets, KoolStorage and other kernel level solutions.
#CdRwLib SDK, WNASPI SDK packages for CD manipulations.
#Offshore development of high quality.
CoolDev.Com
Regards,
Dustin Campbell
Microsys Technologies, Inc.
"Roman" <rom...@servidor.unam.mx> wrote in message news:3d06b555_2@dnews...
....
What crap!!!
An constructor needs to be virtual, when you want to create instances using
a class reference (as Serge already told you). *That* is the most common
reason for making a ctor virtual. Please, have a look at "constructos and
class references" in the Object Pascal Help, where the details are
explained.
PS: Of course, you can override the ctor ... but this "explanation" does not
explain the very special function of virtual ctors.
PPS: It was not intended to harm anyone personally, so there is really no
need for flames.
JensG
virtual constructors only make sens if you have some different class references descending from one base class
small exaple:
TBase = class
constructor Create; virtual; {abstract; }
end;
TBaseClass = class of TBase;
TClassA = class(TBaseClass)
constructor Create; override;
end;
TClassB = class(TBaseClass)
constructor Create; override;
end;
var
abc: array of TBaseClass;
begin
abc[1] := TClassA;
abc[2] := TClassB;
end;
function CreateObjectByNumber(num: Integer): TBase;
begin
result := abs[num].Create;
end;
this is (like) RegisterClass(), GetClass()... work
robert
"Jens Geyer" <j...@vsx.net> wrote:
>
>At first, all of the answers are right.
>At second, another important difference is the presence of the "virtual"
>keyword.
>
>
>.....