[C++-sig] runtime error R6025 - pure virtual function call

Dave Wolfe dwolfe at gforcetech.com
Fri Jan 26 06:54:22 CET 2007


A slightly more streamlined test case, adapted directly from
'exposing.html' in the bpl docs, is appended below.  If anyone can tell
me how to compile this under WinXP without getting the R6025 error, I'll
be much obliged.  Or even if someone else could just try to compile it
under Windows and say "works for me", or "yeah, I'm seeing R6025, too",
it would help a lot.  (I can send the sln and vcproj files if anyone's
interested...)

Thanks,

- Dave W.

P.S.  Interestingly, a colleague of mine was on a Northwest flight a few
weeks ago when his (Linux-based) info-tainment system crashed.  Before
the watchdog caused it to reboot, he saw a similar 'pure virtual
function call' message.  We posited that the software *had* to have been
using some kind of scripting wrapper (or else how would it have even
compiled?) Didn't know when he told me that I'd shortly be seeing the
same thing... :-}

--------------------

# File: pytest.py
from Callable import *

class PyTest(Base):
    def __init__(self):
        Base.__init__(self)
        print "In PyTest.__init__()..."
    def f(self):
        print "In PyTest.f()..."
        return 42


--------------------
// File: Callable.h
#ifndef CALLABLE_H
#define CALLABLE_H

#include <iostream>

struct Base
{
    Base() { std::cout << "In Base::Base()..." << std::endl; }
    virtual ~Base() { }
    virtual int f() = 0;
};

#endif // !CALLABLE_H


--------------------
// File: Callable.cpp

#include <Callable.h>
#include <boost/python.hpp>
#include <boost/noncopyable.hpp>

using namespace boost::python;

struct BaseWrap : Base, wrapper<Base>
{
    int f() { return this->get_override("f")(); }
};

BOOST_PYTHON_MODULE(Callable)
{
    class_<BaseWrap, boost::noncopyable>("Base")
        .def("f", pure_virtual(&Base::f))
        ;
}


--------------------
// File: main.cpp [GetPythonException() omitted for brevity]
#include <Callable.h>
#include <boost/python.hpp>
#include <iostream>

namespace bpl = boost::python;

void CallObject(const char* classType)
{
    Base* obj = NULL;
    try
    {
        bpl::object main = bpl::import("__main__");
        bpl::object global = main.attr("__dict__");
        bpl::exec_file("pytest.py", global, global);
        bpl::object ClassType = global[classType];
        bpl::object myInstance = ClassType();
        obj = bpl::extract<Base*>(myInstance);
    }
    catch (bpl::error_already_set const&)
    {
        std::cerr << GetPythonException();
    }
    
    if (obj) obj->f();
}

int main()
{
    Py_Initialize();
    CallObject("PyTest");
    Py_Finalize();
}

--------------------
[Results of running in interpreter]
E:\projects\Dispatcher\Release>python
ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pytest import *
>>> t = PyTest()
In Base::Base()...
In PyTest.__init__()...
>>> t.f()
In PyTest.f()...
42

[Results of running EXE]
E:\projects\Dispatcher\Release>Dispatcher.exe
In Base::Base()...
In PyTest.__init__()...

runtime error R6025
- pure virtual function call





More information about the Cplusplus-sig mailing list