C ++ / CLI实验 [英] C++/CLI experiments

查看:53
本文介绍了C ++ / CLI实验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我刚刚在VC ++ 2005 Express Beta1中安装了工具刷新,现在它确实被称为Beta版。


我决定检查堆栈上的ref类型,几秒钟之后

的努力我来到这个:


int main()

{

使用命名空间系统;


String s =" Hello world";


Console :: WriteLine(%s);


}


C:\c> cl / clr:safe temp.cpp

Microsoft(R)C / C ++优化编译器版本14.00.40809

(适用于Microsoft(R).NET Framework版本2.00.40607.16

版权所有(C)Microsoft Corporation 。保留所有权利。


temp.cpp

Microsoft(R)增量链接器版本8.00.40809

版权所有(C)Microsoft公司。保留所有权利。


/out:temp.exe

temp.obj


C:\c> ; temp

C:\c>

==>它没有打印Hello world。


上述问题:


上面创建的String对象等同于new字符串(Hello World)?


为什么它不打印任何东西?



祝你好运,


Ioannis Vranos

OK, I just installed the tools refresh in VC++ 2005 Express Beta1, and
now it can indeed be called a Beta.

I decided to check the ref types on stack thing, and after some seconds
of effort I came to this:

int main()
{
using namespace System;

String s="Hello world";

Console::WriteLine(%s);

}

C:\c>cl /clr:safe temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40809
for Microsoft (R) .NET Framework version 2.00.40607.16
Copyright (C) Microsoft Corporation. All rights reserved.

temp.cpp
Microsoft (R) Incremental Linker Version 8.00.40809
Copyright (C) Microsoft Corporation. All rights reserved.

/out:temp.exe
temp.obj

C:\c>temp
C:\c>
==> It doesn''t print "Hello world".

Questions on the above:

The String object created above is equivalent to new String("Hello World")?

Why it doesn''t print anything?


Best regards,

Ioannis Vranos

推荐答案

> int main()
> int main()
{
使用命名空间系统;

String s =" Hello world";

Console :: WriteLine (%s);


C:\ c> cl / clr:safe temp.cpp
Microsoft(R)C / C ++优化编译器版本14.00.40809
Microsoft(R).NET Framework版本2.00.40607.16
版权所有(C)Microsoft Corporation。保留所有权利。

temp.cpp
Microsoft(R)增量链接器版本8.00.40809
版权所有(C)Microsoft Corporation。保留所有权利。

为什么它不打印任何东西?
{
using namespace System;

String s="Hello world";

Console::WriteLine(%s);

}

C:\c>cl /clr:safe temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40809
for Microsoft (R) .NET Framework version 2.00.40607.16
Copyright (C) Microsoft Corporation. All rights reserved.

temp.cpp
Microsoft (R) Incremental Linker Version 8.00.40809
Copyright (C) Microsoft Corporation. All rights reserved.

Why it doesn''t print anything?




Wierd,当我尝试编译上面的内容时,编译器抱怨我不能

在堆栈上分配字符串。我必须用^来引用。


下面的更改使它编译:


#using< mscorlib.dll>


int main()

{

使用命名空间系统;


String ^ s =" ; Hello world" ;;


控制台:: WriteLine(s);


}


- Don Kim



Wierd, when I tried to compile the above, the compler complained I could not
allocate the String on the stack. I had to reference with ^.

The changes below made it compile:

#using <mscorlib.dll>

int main()
{
using namespace System;

String ^s = "Hello world";

Console::WriteLine(s);

}

- Don Kim


> int main()
> int main()
{
使用命名空间系统;

String s =" Hello world";

Console :: WriteLine (%s);


C:\ c> cl / clr:safe temp.cpp
Microsoft(R)C / C ++优化编译器版本14.00.40809
Microsoft(R).NET Framework版本2.00.40607.16
版权所有(C)Microsoft Corporation。保留所有权利。

temp.cpp
Microsoft(R)增量链接器版本8.00.40809
版权所有(C)Microsoft Corporation。保留所有权利。

为什么它不打印任何东西?
{
using namespace System;

String s="Hello world";

Console::WriteLine(%s);

}

C:\c>cl /clr:safe temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40809
for Microsoft (R) .NET Framework version 2.00.40607.16
Copyright (C) Microsoft Corporation. All rights reserved.

temp.cpp
Microsoft (R) Incremental Linker Version 8.00.40809
Copyright (C) Microsoft Corporation. All rights reserved.

Why it doesn''t print anything?




Wierd,当我尝试编译上面的内容时,编译器抱怨我不能

在堆栈上分配字符串。我必须用^来引用。


下面的更改使它编译:


#using< mscorlib.dll>


int main()

{

使用命名空间系统;


String ^ s =" ; Hello world" ;;


控制台:: WriteLine(s);


}


- Don Kim



Wierd, when I tried to compile the above, the compler complained I could not
allocate the String on the stack. I had to reference with ^.

The changes below made it compile:

#using <mscorlib.dll>

int main()
{
using namespace System;

String ^s = "Hello world";

Console::WriteLine(s);

}

- Don Kim


Ioannis,
Ioannis,
好的,我刚刚在VC ++ 2005 Express Beta1中安装了工具刷新,并且
现在它确实可以被称为Beta。

我决定检查堆栈上的ref类型,经过几秒钟的努力,我来到了这个:

int main()
{
使用命名空间系统;

String s =" Hello world";

Console :: WriteLine(% s);


C:\ c> cl / clr:safe temp.cpp
Microsoft(R)C / C ++优化编译器版本14.00。 40809
Microsoft(R).NET Framework版本2.00.40607.16
版权所有(C)Microsoft Corporation。保留所有权利。

temp.cpp
Microsoft(R)增量链接器版本8.00.40809
版权所有(C)Microsoft Corporation。保留所有权利。

/out:temp.exe
temp.obj

C:\ c> temp

C: \c>

==>它没有打印Hello world。

以上问题:

上面创建的String对象相当于new String(" Hello
世界)?
为什么它不打印?
OK, I just installed the tools refresh in VC++ 2005 Express Beta1, and
now it can indeed be called a Beta.

I decided to check the ref types on stack thing, and after some seconds
of effort I came to this:

int main()
{
using namespace System;

String s="Hello world";

Console::WriteLine(%s);

}

C:\c>cl /clr:safe temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40809
for Microsoft (R) .NET Framework version 2.00.40607.16
Copyright (C) Microsoft Corporation. All rights reserved.

temp.cpp
Microsoft (R) Incremental Linker Version 8.00.40809
Copyright (C) Microsoft Corporation. All rights reserved.

/out:temp.exe
temp.obj

C:\c>temp
C:\c>
==> It doesn''t print "Hello world".

Questions on the above:

The String object created above is equivalent to new String("Hello World")?
Why it doesn''t print anything?




哎哟!看起来像编译器错误,对我来说。看看生成的代码,一个

可以看到编译器正在加载s为null,而不是对

字符串的引用:(


您可能想报告....

-

Tomas Restrepo
**** @ mvps.org


这篇关于C ++ / CLI实验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆