logo       

Problem with Swig Pure virtual functions: msg#00083

programming.swig

Subject: Problem with Swig Pure virtual functions

Hello everyone,
I apologize for sending a really long email, but I'd really appreciate it, if someone could give me a solution
I just downloaded SWIG 1.3.22, since I want to access my C++ library from a perl script.
When I used pure virtual functions, I ran into a problem, where the wrapper file generated by swig refused to compile.
Here's a simple example representing my problem.
 
I used it on Red Hat 9, with g++ 3.2.2.
 
The interface file, header file, source code is pasted below, followed by my shell commands, followed by the compiler output
 
Thanks, in advance,
Swaroop Sayeram
 
 
/*
Interface file - farmer.i
*/
%module farmer
%{
 /* Includes the header in the wrapper code */
#include "farmer.h"
%}
 
 
 
/*
Header File - farmer.h
*/
 
class Farmer_Parent {
 public:
  virtual Farmer_Parent* Copy( ) const = 0;
};
 

 class Farmer : public Farmer_Parent {
   public:
     Farmer(char *name, int age);
     Farmer();
     ~Farmer();
     int how_tired() { return tiredness; }
     int how_long() { return howlong; }
     void do_chores(int howlong);
     virtual Farmer_Parent *Copy( ) const;
   private:
     char *name;
     int age;
     int tiredness;
     int howlong;
   };
 
 
/*
C++ File - farmer.c
*/
#include"string.h"
#include"stdlib.h"
#include "farmer.h"
 
 
Farmer::Farmer(char *name, int age) {
  this->name = strdup(name);
  this->age = age;
  tiredness = 0;
  howlong = 0;
}
Farmer::~Farmer() {
  free(name);
}
void Farmer::do_chores(int hl) {
  howlong += hl;
  tiredness += (age * hl);
}

Farmer_Parent*
Farmer::Copy() const {
  Farmer* f = new Farmer();
  return f;
}
 
 
$swig -perl5 -c++ farmer.i
$g++ -c -fpic -Dexplicit= farmer.c farmer_wrap.cxx -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -isystem /usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -I/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE

In file included from farmer_wrap.cxx:869:
farmer.h:3:32: macro "Copy" requires 4 arguments, but only 1 given
In file included from farmer_wrap.cxx:869:
farmer.h:3: `Copy' declared as a `virtual' field
farmer.h:3: parse error before `const'
farmer.h:15:35: macro "Copy" requires 4 arguments, but only 1 given
farmer.h:15: `Copy' declared as a `virtual' field
farmer.h:15: parse error before `const'
farmer_wrap.cxx:908:71: macro "Copy" requires 4 arguments, but only 1 given
farmer_wrap.cxx:1139:64: macro "Copy" requires 4 arguments, but only 1 given

 
 
 
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise