本文介绍了在非托管类中混合Mananged和Unmanaged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否可以编写课程,取决于课堂上的功能顺序。


我的问题是(见下面的例子):

1)类''WillCompile''将编译和执行,或者是
2)是一个错误,还是类'WillNotCompile''不能编译的错误? br />

#include" stdafx.h"

#include< iostream>

#include< memory>

使用命名空间std;


#using< mscorlib.dll>


使用命名空间系统;


#pragma unmanaged

类WillCompile {

public:

static void Umg(){

}

#pragma managed

static void Mng(String * str){

Console :: WriteLine(str);

}

};


#pragma unmanaged

class WillNotCompile {

public:

#pragma managed

static void Mng(String * str){

Console :: WriteLine(str);

}

#pragma unmanaged

static void Umg(){

}

};


#pragma managed

int _tmain()

{

WillCompile :: Mng(S" This works。 );


Console :: WriteLine(S"按Enter键继续。);

Console :: ReadLine();

返回0;

}

Whether I can compile a class or not, depends on the order of functions in my class.

My question is (see example below):
1) Is it a bug that the class ''WillCompile'' will compile and execute, or
2) or is it a bug that the class ''WillNotCompile'' will not compile?.

#include "stdafx.h"
#include <iostream>
#include <memory>
using namespace std;

#using <mscorlib.dll>

using namespace System;

#pragma unmanaged
class WillCompile {
public:
static void Umg() {
}
#pragma managed
static void Mng( String* str ) {
Console::WriteLine( str );
}
};

#pragma unmanaged
class WillNotCompile {
public:
#pragma managed
static void Mng( String* str ) {
Console::WriteLine( str );
}
#pragma unmanaged
static void Umg() {
}
};

#pragma managed
int _tmain()
{
WillCompile::Mng( S"This works." );

Console::WriteLine(S"Press Enter to continue.");
Console::ReadLine();
return 0;
}

推荐答案





我们的Visual C ++团队成员Ronald确认这两个场景都是

设计,简单的规则是:任何触及托管类型的代码必须是编译为MSIL的
,任何无法编译的代码都可以编译。


你对这个问题有什么特别的期望或关注,如果是的话,

请随时回复此信息。

谢谢!


祝你好运,

Gary Chang

微软在线合作伙伴支持


安全! -

此帖子原样是按原样提供的。没有保证,也没有赋予任何权利。

--------------------



Our Visual C++ team member Ronald confirmed these 2 scenarios are both as
designed, simply the rule is: any code that touches managed types must be
compiled as MSIL, any code that does not can be compiled either way.

Do you have any particular expectation or concern on this problem, if so,
please feel free to reply this message.
Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------



这篇关于在非托管类中混合Mananged和Unmanaged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 02:20