« Return to Thread: Basic C++ Question

Basic C++ Question

by aasmith :: Rate this Message:

Reply to Author | View in Thread

I'm trying to use SWIG on some basic C++ files.  My code follows at the
end of this note.  Basically, SWIG seems to work just fine, until I try to
compile the resulting wrapper.cxx file.  When I do that, I get a ton of
errors.  They look like scoping errors, but the wrapper code is
complicated enough that I'm really not sure.

$ swig -python -c++ Stupid.i
$ g++ -c -fpic Stupid_wrap.cxx -I/usr/include/python2.6/
Stupid_wrap.cxx: In function PyObject* _wrap_new_Stupid(PyObject*, PyObject*):
Stupid_wrap.cxx:2765: error: Stupid was not declared in this scope
Stupid_wrap.cxx:2765: error: result was not declared in this scope
Stupid_wrap.cxx:2773: error: expected primary-expression before ) token
Stupid_wrap.cxx:2773: error: expected `;' before new

(and many more)

This happens regardless of which language I try to use (Python, Perl,
Java, etc.).  It's also happened for other, more complicated files.  I've
been banging my head against my monitor on this one for a few days--any
help would be welcome.

Thanks,
Adam

Stupid.cpp:

#include "Stupid.h"

using namespace std;

Stupid::Stupid(int n) {
   number = new int(1);
   *number = n;
}

Stupid::~Stupid(void) {
   delete number;
}

int Stupid::getNumber(void) {
   return *number;
}

void Stupid::setNumber(int n) {
   *number = n;
}

void Stupid::printNumber(void) {
   cout << *number << "\n";
}


Stupid.h:

#include <iostream>

#ifndef STUPID_DEFINED
#define STUPID_DEFINED

class Stupid {
  private:
   int *number;
  public:
   Stupid(int n);
   ~Stupid(void);
   int getNumber(void);
   void setNumber(int n);
   void printNumber(void);
};

#endif

Stupid.i:

%module stupid
%{
#include <iostream>
%}

class Stupid {
   private:
     int *number;
   public:
     Stupid(int n);
     ~Stupid(void);
     int getNumber(void);
     void setNumber(int n);
     void printNumber(void);
};


------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

 « Return to Thread: Basic C++ Question