POV-Ray : Newsgroups : povray.off-topic : Wahahahaha! : Re: Wahahahaha! Server Time
11 Oct 2024 23:12:13 EDT (-0400)
  Re: Wahahahaha!  
From: Darren New
Date: 9 Nov 2007 00:00:55
Message: <4733e987$1@news.povray.org>
Warp wrote:
>   I think that error happens if you try to call a pure virtual function
> in the initialization list of the base class constructor. (What I really
> don't understand is why it isn't a compile-time error...)

Just to check, by "pure virtual function", you mean the kind of thing 
that leads to the class being abstract? A function like
   virtual int func() = 0;
or whatever the syntax is?

Oh, right, OK. So it's called in the constructor of the class that 
actually implements the virtual function, except it's called before the 
child's constructor actually gets entered, so the vtable pointer is 
still pointing to the parent's vtable or whatever so the parent has the 
right offsets for its stuff, ....

I can see where catching that would be difficult. If the constructor 
calls x(), and x() calls y(), and y() is abstract in the parent class, 
C++ is going to invoke a function whose definition isn't there.

Most other languages don't futz with the class of the object while it's 
being constructed, so it doesn't really come up, I guess. One of the 
costs of multiple inheritance as implemented by C++?

-- 
   Darren New / San Diego, CA, USA (PST)
     Remember the good old days, when we
     used to complain about cryptography
     being export-restricted?


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.