Re: Bless, inheritance and swig

From: Xiaodong Huang (xhuang_at_yahoo.com)
Date: 03/31/04


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



Relevant Pages

  • [SLE] Problem installing perl DBD::mysql for mtop
    ... I am trying to get the MySQL performance monitoring tool "mtop" running ... However I get errors when trying to install the perl DBD::mysql package. ... skipping incompatible /lib/libc.so.6 when searching for ...
    (SuSE)
  • Re: SED or COBOL to insert a line in many programs?
    ... > searching for some text that each program has and ... Native Unix filesystems are case-sensitive. ... unless you have good reason to suspect that the effort ... Many Unix programmers, by the way, would use Perl for this. ...
    (comp.lang.cobol)
  • Re: Doing the Impossible? :: Is there anyway to access custom .Net DLLs from within Perl
    ... but searching for "perl 'accessing dll'" ... The problem is not getting perl to use DLLs, ... stated that can be easily done, but .Net DLLs are a little trickier. ... that knows how to load and start the CLR and then load the ...
    (comp.lang.perl.misc)
  • Re: Port forwarding utility in perl
    ... DM> I am searching for a port forwarding package in perl, ... --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- ... Search or Offer Perl Jobs ...
    (comp.lang.perl.misc)