Rubyo wrote:
> Juan Manuel Alvarez wrote:
>>> Hi everyone!
>>>
>>> I am trying to wrap an abstract class to C#, but I always get the
>>> "cannot instantiate abstract class" error, since SWIG generates a
>>> construction function.
>>>
This shouldn't happen by default. Please show a minimal example
demonstrating the problem if you want any more advice.
>> You should be able to turn off automatic constructor generation with the
>> %nodefaultctor feature flag directive. See the manual:
>>
http://www.swig.org/Doc1.3/SWIGDocumentation.html#SWIGPlus_nn8>>
> I'm trying to solve the same situation..
> ..the problem is tha you don't have the body of the pure virtual
> function .. so eliminating the constructor is not a solution ... I think
> ...( or I'm wrong ? )...swig translate the abstract class as a usual
> class ( not interface! ) and try to instantiate it anyway... so you get
> that error ... or is there some news on that?
>
> anyway in the manul page you read .. "Default constructors are not
> generated for classes with pure virtual methods or for classes that
> inherit from an abstract class, but don't provide definitions for all of
> the pure methods."...
>
Stefano, I have an example of how to wrap abstract base classes which
I've pasted below. It is for Java, but with a bit of modification can be
made to work for C#. Just modify the typemap names as described in the
CSharp.html documentation, eg javabody->csbody. The example shows how
multiple inheritance can be made to work, even though there is a lot of
swig machinery to write. As Zhiyang Jiang mentioned in another thread,
he might be able to modify swig so that just one line of code can
replace all of the typemaps and features below.
William
/* File : example.i */
%module example
// Turn the proxy class into an interface
%typemap(javaclassmodifiers) IRemoteSyncIO "interface";
%typemap(javaclassmodifiers) IRemoteAsyncIO "interface";
%typemap(javabody) IRemoteSyncIO "";
%typemap(javabody) IRemoteAsyncIO "";
%typemap(javafinalize) IRemoteSyncIO "";
%typemap(javafinalize) IRemoteAsyncIO "";
%typemap(javadestruct) IRemoteSyncIO "";
%typemap(javadestruct) IRemoteAsyncIO "";
// Turn the methods into abstract methods
%javamethodmodifiers IRemoteSyncIO::syncmethod "abstract public";
%javamethodmodifiers IRemoteAsyncIO::asyncmethod "abstract public";
%typemap(javaout) void IRemoteSyncIO::syncmethod ";"
%typemap(javaout) void IRemoteAsyncIO::asyncmethod ";"
// Features are inherited by derived classes, so override this
%javamethodmodifiers RemoteMpe::syncmethod "public"
%javamethodmodifiers RemoteMpe::asyncmethod "public"
// Modify multiple inherited base classes into inheriting interfaces
%typemap(javainterfaces) RemoteMpe "IRemoteSyncIO, IRemoteAsyncIO";
%typemap(javabase, replace="1") RemoteMpe "";
%inline %{
class IRemoteSyncIO
{
public:
virtual ~IRemoteSyncIO () {}
virtual void syncmethod() = 0;
protected:
IRemoteSyncIO () {}
private:
IRemoteSyncIO (const IRemoteSyncIO&);
IRemoteSyncIO& operator= (const IRemoteSyncIO&);
};
class IRemoteAsyncIO
{
public:
virtual ~IRemoteAsyncIO () {}
virtual void asyncmethod() = 0;
protected:
IRemoteAsyncIO () {}
private:
IRemoteAsyncIO (const IRemoteAsyncIO&);
IRemoteAsyncIO& operator= (const IRemoteAsyncIO&);
};
class RemoteMpe : public IRemoteSyncIO, public IRemoteAsyncIO
{
public:
virtual void syncmethod() {}
virtual void asyncmethod() {}
};
%}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user