473,322 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Wrapping classes with pure virtual functions

Hi,
I'm having problems wrapping a hierarchy of classes, actually having
problems wrapping the base class. I don't need to use the WrapClass
mechanism since I don't want to override classes in Python. My code
boils down to:

class Base
{
public:
virtual ~Base()
{}

virtual void f() = 0;
};

class Derived :
public Base
{
public:
virtual void f()
{}

void g()
{}
};

int main()
{
boost::python::class_<Baseclass_base("Base");
boost::python::class_<Derivedclass_derived("Derive d");
return 0;
}

The first line inside main (the one exporting Base) is causing the
compile time error:
error C2259: 'Base' : cannot instantiate abstract class...
The probem seems to be that struct value_holder<Baseholds a Base
member instance by value, and this is not possible since Base can't be
instantiated.
I'm using Visual Studio 2005 and boost 1.33.1.
Thanks

Dec 14 '06 #1
3 2862
On Thu, Dec 14, 2006 at 01:57:10PM -0800, ga****************@gmail.com wrote:
Hi,
I'm having problems wrapping a hierarchy of classes, actually having
problems wrapping the base class. I don't need to use the WrapClass
mechanism since I don't want to override classes in Python. My code
boils down to:

class Base
{
public:
virtual ~Base()
{}

virtual void f() = 0;
};

class Derived :
public Base
{
public:
virtual void f()
{}

void g()
{}
};

int main()
{
boost::python::class_<Baseclass_base("Base");
Why are you trying to make this type visible to python? It is pure virtual,
you can never instantiate it.
boost::python::class_<Derivedclass_derived("Derive d");
return 0;
}

The first line inside main (the one exporting Base) is causing the
compile time error:
error C2259: 'Base' : cannot instantiate abstract class...
The probem seems to be that struct value_holder<Baseholds a Base
member instance by value, and this is not possible since Base can't be
instantiated.
I'm using Visual Studio 2005 and boost 1.33.1.
Thanks

--
http://mail.python.org/mailman/listinfo/python-list
Dec 17 '06 #2

Chris Lambacher wrote:
On Thu, Dec 14, 2006 at 01:57:10PM -0800, ga****************@gmail.com wrote:
Hi,
I'm having problems wrapping a hierarchy of classes, actually having
problems wrapping the base class. I don't need to use the WrapClass
mechanism since I don't want to override classes in Python. My code
boils down to:

class Base
{
public:
virtual ~Base()
{}

virtual void f() = 0;
};

class Derived :
public Base
{
public:
virtual void f()
{}

void g()
{}
};

int main()
{
boost::python::class_<Baseclass_base("Base");
Why are you trying to make this type visible to python? It is pure virtual,
you can never instantiate it.
Because I want to use subclasses of Base polymorphically from Python.
Python will receive an instance of some Base subclass through a another
exported function.
boost::python::class_<Derivedclass_derived("Derive d");
return 0;
}

The first line inside main (the one exporting Base) is causing the
compile time error:
error C2259: 'Base' : cannot instantiate abstract class...
The probem seems to be that struct value_holder<Baseholds a Base
member instance by value, and this is not possible since Base can't be
instantiated.
I'm using Visual Studio 2005 and boost 1.33.1.
Thanks

--
http://mail.python.org/mailman/listinfo/python-list
Dec 17 '06 #3
ga****************@gmail.com wrote:
Chris Lambacher wrote:
On Thu, Dec 14, 2006 at 01:57:10PM -0800, ga****************@gmail.com wrote:
Hi,
I'm having problems wrapping a hierarchy of classes, actually having
problems wrapping the base class. I don't need to use the WrapClass
mechanism since I don't want to override classes in Python. My code
boils down to:
>
class Base
{
public:
virtual ~Base()
{}
>
virtual void f() = 0;
};
>
class Derived :
public Base
{
public:
virtual void f()
{}
>
void g()
{}
};
>
int main()
{
boost::python::class_<Baseclass_base("Base");
Why are you trying to make this type visible to python? It is pure virtual,
you can never instantiate it.

Because I want to use subclasses of Base polymorphically from Python.
Python will receive an instance of some Base subclass through a another
exported function.
I don't know much about Boost. Does it have anything like
boost::python::pointer_<Base>?

You can't get polymorphism by direct access to a class. C++ compiler
always knows the exact type of a direct, non-pointer-accessed object.
So even if you could create a class_<Base>, it would only ever be a
Base, and never a derived class. You have to use pointers to get
polymorphism.

As an alternative, consider wrapping the derived classes instead. It
might not be much more work if Boost wraps everything nicely.
Carl Banks

Dec 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: verbatime | last post by:
Please explain me how this works - or should work: Got my two classes - bcBasic (baseclass) and the derived cBasic. //--------------------------------------- class bcBasic { int number;...
11
by: mem | last post by:
Concrete classes are ones that can be instantiated directly, as long as it doesn't have pure virtual function. However, people suggest that "Don't derive from concrete classes." Does this mean...
5
by: Lee Crabtree | last post by:
More fun wrapping unmanaged code... I have a class heirarchy that I need to expose to C#, so I need to wrap all the classes. That's not a big deal, except for the base class, which is abstract....
6
by: konstantin.kivi | last post by:
Hello All We have a system where customer request (of text form) are processed. The number of different request types is more than a thousand. With current ( C-langauage ) design request a...
10
by: Tom the Canuck | last post by:
What would be the best way to proceed? Should I make a pure virtual class and then derive from that? I want the base class to have functions defined so that I don't have to do the work all over...
6
by: Alden Pierre | last post by:
Hello, http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.7 As per the link above it's wise to have a virtual deconstructor when creating an abstract class. Here is when I'm...
6
by: ivan.leben | last post by:
I want to write a Mesh class using half-edges. This class uses three other classes: Vertex, HalfEdge and Face. These classes should be linked properly in the process of building up the mesh by...
17
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;"...
6
by: Miguel Guedes | last post by:
Hello, I recently read an interview with Bjarne Stroustrup in which he says that pure abstract classes should *not* contain any data. However, I have found that at times situations are when it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.