Re: Bless, inheritance and swig
From: Xiaodong Huang (xhuang_at_yahoo.com)
Date: 03/31/04
- Next message: Brad Baxter: "Re: trapping errors"
- Previous message: Pat Garner: "Module install help?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 31 Mar 2004 11:47:53 -0800
Brad Baxter <bmb@ginger.libs.uga.edu> wrote in message news:<Pine.A41.4.58.0403302118580.14252@ginger.libs.uga.edu>...
> On Tue, 30 Mar 2004, Xiaodong Huang wrote:
>
> > I searched but could not find answer for this question on Internet or
> > in Newsgroups.
> >
> > I have a class CObject in C++ which is wrapped by SWIG:
> >
> > class CObject {
> > public:
> > CObject();
> > get();
> > }
> >
> > I want to write a perl object that inherits from
> > CObject. So I wrote something like this (I used similar code
> > before in non-SWIG case):
> >
> > Package MyPerlObject;
> --^
> s/P/p/;
>
>
> >
> > use Exporter;
>
> FWIW, you probably don't need Exporter.
>
>
> > use CObject;
> >
> > our @ISA = qw(CObject Exporter);
> >
> > sub new {
> > my $class = shift ;
> > $class = ref($class) || $class ;
> > my $self = CObject->new();
> > bless $self, $class;
> > return $self;
> > }
> >
> > ...
> >
> > MyPerlObject does not have a method get(). When client of MyPerlObject
> > called MyPerlObject::get() at run-time, I got
> > "No matching function for overloaded CObject_get()".
> >
> > So I tried to pinpoint where the problem was and found that it seemed
> > to have something to do with bless.
> >
> > I modified the above new() subroutine by adding two lines:
> >
> > sub new {
> > my $class = shift ;
> > $class = ref($class) || $class ;
> > my $self = CObject->new();
> > $self->get(); # works
> > bless $self, $class;
> > $self->get(); # does not work
> > return $self;
> > }
> >
> > The line before "bless" statement works but the line after it gives me
> > the "No matching function .." error as before.
> >
> > Could someone point to me what I did wrong or suggest a way to work around
> > the problem?
> >
> > Thanks.
> >
> > xh
> >
>
> package CObject;
>
> sub get { print "CObject::get ran\n" }
> sub new { bless {}, $_[0] }
>
> package MyPerlObject;
>
> our @ISA = qw(CObject);
>
> sub new {
> my $class = shift ;
> $class = ref($class) || $class ;
> my $self = CObject->new();
> $self->get(); # works
> bless $self, $class;
> $self->get(); # does not work (does now)
> return $self;
> }
>
> my $o = MyPerlObject->new();
>
> __END__
> CObject::get ran
> CObject::get ran
>
>
> Hope that helps,
>
> Brad
Brad,
If CObject is a plain perl class, it's get() method can be located by
its derived class. The problem arises when CObject
is a C++ class wrapped by SWIG interface. Hence the message "No matching
function for overloaded CObject_get()".
still searching for solution..
Thanks.
xh
- Next message: Brad Baxter: "Re: trapping errors"
- Previous message: Pat Garner: "Module install help?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|