ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> cpp-sig
cpp-sig
[C++-sig] Virtual methods
by Nicodemus other posts by this author
Feb 25 2003 3:45PM messages near this date
Re: [C++-sig] problem wrapping a c++ function on windows | Re: [C++-sig] Virtual methods
Hi!

I'm using Intel C++, STLport 4.5.3 and the current CVS.

I can't get the simple example from the tutorial about virtual methods to work. 
I copied and pasted the example, but couldn't reproduce the correct behaviour in 
python:

// basic.cpp

#include <boost/python.hpp> 

using namespace boost::python;

struct Base
{
     virtual int f() = 0;
};

int call_f(Base& b) { return b.f(); }

struct BaseWrap : Base
{
     BaseWrap(PyObject* self_)
         : self(self_) {}
     int f() { return call_method<int> (self, "f"); }
     PyObject* self;
};


// Module ======================================================================
BOOST_PYTHON_MODULE(basic)
{
     class_<Base, BaseWrap, boost::noncopyable> ("Base", no_init)
         ;
     def("call_f", call_f);

}



 > >> from basic import *
 > >> class Derived(Base):
...     def f(self):
...             return 42
...
 > >> d = Derived()
Traceback (most recent call last):
   File "<stdin> ", line 1, in ?
RuntimeError: This class cannot be instantiated from Python
 > >>
 > >> # hmmm... let's override the __init__ method and see
 > >> # what happens
 > >> class Derived(Base):
...     def __init__(self): pass
...     def f(self): return 42
...
 > >> d = Derived()
 > >> call_f(d)
Traceback (most recent call last):
   File "<stdin> ", line 1, in ?
TypeError: bad argument type for built-in operation
 > >>

I remember using this example before, and it did work... has something changed 
since then?


Thanks,
Nicodemus.



_______________________________________________
C++-sig mailing list
C++-sig@[...].org
http://mail.python.org/mailman/listinfo/c++-sig
Thread:
Nicodemus
David Abrahams
Nicodemus

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved