读书人

C++ CLI global function 有关问题 分

发布时间: 2012-01-09 21:05:42 作者: rapoo

C++ CLI global function 问题 分不多了 谢谢
C++/CLI in action 中 有这么一段
You can specify the abstract and sealed modifiers on classes; a class can be marked both abstract and sealed. But such classes can’t be derived explicitly from any base class and can only contain static members. Because global functions aren’t CLS-compliant, you should use abstract sealed classes with staticfunctions, instead of global functions, if you want your code to be CLS-compliant.

下面是我 2005 下的代码 项目属性中 公共语言运行库的选项已经选为 /CLR
但代码编译运行 没有抱错 这是为何 ? 不是说不能用全局函数么?
谢谢!

#include "stdafx.h "

using namespace System;

ref class RefClass{
void fun(){
System::Console::WriteLine( "test ");
}
};

ref struct RefClass2{
void Func(){
System::Console::WriteLine( "test ");
}
};

void fun(){
System::Console::WriteLine( "gloable fun ");
}

int main(array <System::String ^> ^args)
{
Console::WriteLine(L "Hello World ");
RefClass2 c;
c.Func();

fun();
return 0;
}

[解决办法]
如果是在团队

你的程序将被你的团队排挤在外(不能链接在一起)

自己单练的话 ,和你的程序在其它系统或机子上不兼容

[解决办法]
我觉得没什么问题,就是你编译之后里边会含有二进制代码。
因为,全局函数不能生成CLR代码。
其他的人应该可以使用你的程序。如果都是在Windows上应该没什么不兼容的吧?
你试试用/clr:pure应该会出错吧?

读书人网 >VC

热点推荐