POV-Ray : Newsgroups : povray.off-topic : C++ question : Re: C++ question Server Time
29 Sep 2024 13:25:31 EDT (-0400)
  Re: C++ question  
From: Warp
Date: 8 Apr 2009 16:39:03
Message: <49dd0b67@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> How is it possible to invoke a virtual method that wasn't defined?  I.e., I 
> have a superclass that declares
>    void abc(int) = 0;

> What's happening that I can instantiate a child of that class without that 
> method defined, and then try to invoke the method? As far as I understand, 
> the type system should be preventing that, shouldn't it?

  If your compiler allows you to instantiate a class with pure virtual
functions, then your compiler is horribly buggy. Normally you should get
a compilation error along the lines of:

test.cc: In function 'int main()':
test.cc:13: error: cannot declare variable 'b' to be of abstract type 'B'
test.cc:8: note:   because the following virtual functions are pure within 'B':
test.cc:4: note:        virtual void A::abc(int)

  I guess that you are not really instantiating an abstract class, or either
you are doing something really weird which somehow is able to bypass the
compiler checks (in which case you get UB, of course).

-- 
                                                          - Warp


Post a reply to this message

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