POV-Ray : Newsgroups : povray.off-topic : C++ question : Re: C++ question Server Time
29 Sep 2024 13:25:06 EDT (-0400)
  Re: C++ question  
From: Warp
Date: 9 Apr 2009 03:00:30
Message: <49dd9d0e@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> I don't know. I've seen it happen at runtime with "trying to invoke pure 
> virtual function" on Windows, and now I'm getting some of the same sorts of 
> messages from a Linux program (from a place where you're supposed to fill in 
> as you port it, so not entirely unexpected).

  That runtime error can happen when you call a pure virtual function from
the base class constructor (even if the object being instantiated is not
abstract). In other words:

class Base
{
 public:
    virtual void function() = 0;

    Base() { function(); }
};

  I'm not exactly sure how standard that behavior is, though. At least in
a current version of gcc you get both a warning and a linker error in this
situation if Base::function() has no implementation. However, I do remember
that in older versions of gcc it would compile and you would then get the
runtime error.

  (If the pure virtual function has an implementation in Base, what will
end happening is that this Base implementation gets called, rather than
the implementation in the derived class. Hence the warning.)

-- 
                                                          - Warp


Post a reply to this message

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