Duc*_*een 4 .net c# c++ inheritance swig
因此,在C ++中有一个简单的代码。有一个C ++库,具有:
class A{
public:
    virtual void Call();
    virtual void CallCall();
    virtual ~A();
};
还有一个swig文件:
%{
#include "A.h"
%}
%include "A.h"
%module(directors="1") TestSWIG;
%feature("director") A;
在调用SWIG generator之后,将生成的C ++和C#文件包含到相关项目中并重建所有项目。
swig.exe -c ++ -csharp-命名空间TestSWIG -outdir ./Sharp/TestSWIG -o ./TestSWIG.cxx TestSWIG.i
我们希望一个简单的C#.Net代码可以工作:
using System;
using TestSWIG;
namespace ASharp {
    class Cassa : A{
        public override void Call() {
            Console.WriteLine("Hello from C#");
        }
    }
    class Program {
        private static void Main(string[] args) {
            var c = new Cassa();
            c.CallCall();
            Console.ReadLine();
        }
    }
}
但是我们看到C ++实现被称为
void A::Call() {
    std::cout << "Hello from C++ World!" << std::endl;
}
现在的问题是:我该怎么做才能使继承和虚函数不起作用?
答案是...查看Swig-> Examples!==)问题出在.i文件排序中。
%module(directors="1") TestSWIG; // Module name
// Source code refrence
%{
#include "A.h"
%}
%feature("director") A; // objects to support inheritance
%include "A.h" // main file to parse
并按要求工作!=)