[英]Why SWIG C# overloads fail?
So having a simple code in C++ . 所以在C ++中有一个简单的代码 。 Having a C++ library with:
拥有一个C ++库:
class A{
public:
virtual void Call();
virtual void CallCall();
virtual ~A();
};
And a swig file: 一个swig文件:
%{
#include "A.h"
%}
%include "A.h"
%module(directors="1") TestSWIG;
%feature("director") A;
After calling SWIG generator, including generated C++ and C# files into related projects and rebuilding all projects. 调用SWIG生成器后,包括生成的C ++和C#文件到相关项目中并重建所有项目。
swig.exe -c++ -csharp -namespace TestSWIG -outdir ./Sharp/TestSWIG -o ./TestSWIG.cxx TestSWIG.i
swig.exe -c ++ -csharp -namespace TestSWIG -outdir ./Sharp/TestSWIG -o ./TestSWIG.cxx TestSWIG.i
We want a simple C# .Net code to work: 我们想要一个简单的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();
}
}
}
Yet we see that C++ implementation is the one that gets called 然而,我们看到C ++实现是被调用的实现
void A::Call() {
std::cout << "Hello from C++ World!" << std::endl;
}
Now the question is: what do I do wrong so that inheritance and virtual functions do not work? 现在的问题是:我做错了什么,以便继承和虚函数不起作用?
And the answer was... to look into Swig->Examples!=) The problem was in ordering in a .i
file. 答案是......查看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
and it worked as required!=) 它按要求工作!=)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.