
可以使用C++/CLI在C++和.Net之间联合编程,C++/CLI是一个两栖模块,它具有如下特点
使用C++/CLI,可以使用C++编写算法,用C#编写界面
C++/CLI(Common Language Infrastructure,通用语言框架)可以简单的认为就是.NET运行的托管C++
C#可以调用Native C++类,也可以调用C++/CLI类,但是区别非常大。
C++/CLI声明的类必须是ref类,即声明方式只能是:
ref class major{};
ref struct major{};
C++/CLI调用C#,在C++/CLI文件内引用C#类库文件和命名空间即可
#using "LMath.dll" using namespace My::LMath;
String^ fileName = "textfile.txt"; StreamWriter^ sw = gcnew StreamWriter(fileName);
If you use the sample program, notice thatyou use the gcnew keyword instead of new when creating a .NET object,and that gcnew returns a handle( ^ ) rather than a pointer ( * ):
using namespace System;
using namespace System::IO;
int main()
{
String^ fileName = "textfile.txt";
StreamWriter^ sw = gcnew StreamWriter(fileName);
sw->WriteLine("Hi Major");
sw->Close();
Console::WriteLine("a new file ('{0}') has been written", fileName);
return 0;
}
public ref class Point; int x,y; public ref class ContourFinder void load_picture(System::String^ file_name); List参考文档^>^ find_contour(int threshold); property int Rows {int get();} property int cols {int get();}