C ++ / CLI 2005中的错误 [英] Bug in C++ /CLI 2005

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

问题描述

问候:


是否有人知道C ++ / CLI 2005中明显错误的修复...


如果您创建具有使用堆栈语义声明的ref类型成员变量的类,并且将此成员声明为[NonSerialized],当您反序列化此类类型的对象时,该成员不能再使用。


它本质上是孤儿。


帮助...

Greetings:

Is anyone aware of a fix for the apparent bug in C++ /CLI 2005...

If you create a class with a ref type member variable declared with stack semantics and you declare this member as [NonSerialized], when you deserialize an object of this class type, the member can no longer be used.

It is essentially orphaned.

Help...

推荐答案

更多信息..当我说基本孤立我的意思是,如果你的成员归属于NonSerialized,那么使用堆栈语义声明的事件发生在堆上的魔法在反序列化时不会发生。此外,因为它是用堆栈语义声明的,所以不再有任何方式为它分配存储,因此是孤立的。


通常孤立意味着已经分配了内存并且不再有任何方式引用它。在这种情况下,我有一个参考,没有办法为它分配内存。

" Howard Swope" < howard_swopeAThms3DOTcomwrote in message news:%2 **************** @ TK2MSFTNGP05.phx.gbl ...

问候:


是否有人知道C ++ / CLI 2005中明显错误的修复...


如果创建一个带有使用堆栈声明的ref类型成员变量的类语义并且您将此成员声明为[NonSerialized],当您反序列化此类类型的对象时,该成员将无法再使用。


它基本上是孤立的。


帮助...
A bit more info... when I say essentially orphaned what I mean is that the magic that happens to make things declared with stack semantics get placed on the heap doesn''t happen on deserialization if your member is attributed with NonSerialized. Also, because it is declared with stack semantics there is no longer any way to assign storage to it, thus orphaned.

Usually orphaned means that memory has been allocated and there is no longer anyway to refer to it. In this case I have a reference and no way to assign memory to it.
"Howard Swope" <howard_swopeAThms3DOTcomwrote in message news:%2****************@TK2MSFTNGP05.phx.gbl...
Greetings:

Is anyone aware of a fix for the apparent bug in C++ /CLI 2005...

If you create a class with a ref type member variable declared with stack semantics and you declare this member as [NonSerialized], when you deserialize an object of this class type, the member can no longer be used.

It is essentially orphaned.

Help...


" Howard Swope" < howard_swopeAThms3DOTcom在消息新闻中写道:%2 **************** @ TK2MSFTNGP05.phx.gbl ...

我不知道是不是'是一个错误或设计。


反序列化对象时,很可能不会使用堆栈语义创建新对象。


成员变量仍然存在,但它未初始化,可能是因为只有使用C ++编译器编译的代码才能使用堆栈语义来创建对象。

我会说这个bug首先允许一个带有堆栈语义的成员变量。它可能使得该类在C ++之外无法使用。


Mark


-

Mark Salsbery
Microsoft MVP - Visual C ++

问候:


是否有人知道修复了C ++ / CLI 2005中的明显错误...


如果创建一个带有使用堆栈语义声明的ref类型成员变量的类,并将此成员声明为[NonSerialized],则在对此类类型的对象进行反序列化时,该成员可以不再使用。


它基本上是孤儿。


帮助...

"Howard Swope" <howard_swopeAThms3DOTcomwrote in message news:%2****************@TK2MSFTNGP05.phx.gbl...
I don''t know if that''s a bug or by design.

When the object is deserialized, a new object is created most likely NOT using stack semantics.

The member variable is still there, but it is uninitialized, probably because only code compiled with the C++ compiler is capable of using stack semantics to create objects.

I''d say the bug is allowing a member variable with stack semantics in the first place. It probably makes the class unusable outside of C++.

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++
Greetings:

Is anyone aware of a fix for the apparent bug in C++ /CLI 2005...

If you create a class with a ref type member variable declared with stack semantics and you declare this member as [NonSerialized], when you deserialize an object of this class type, the member can no longer be used.

It is essentially orphaned.

Help...


Mark:


使用堆栈语义声明变量是C ++ CLI中的一个广告功能,非常有用。对我们来说,它特别有用,因为我们使用了一个非托管的引用计数对象库。我们已经创建了托管智能指针来保存它们并处理所有引用计数问题。唯一真正的方法是重载所有指针运算符。如果用gcnew初始化它们,这确实不起作用。这肯定不是一个功能。反序列化后,没有与变量关联的存储空间,也无法再次使用该变量。你不能将gcnew与使用堆栈语义声明的变量一起使用。


这些智能指针对我们的代码至关重要。我应该在3个月内发布这个产品,现在看起来我将不得不在hunderd类上手动实现ISerializable。我会让我的代码基础量级更容易出错。如果我没有为此工作,我是@#
Mark:

Declaring variables with stack semantics is one of the Advertised features in C++ CLI and a very useful one. For us it is especially useful because we have an unmanaged library of referenced counted objects that we use. We have created managed smart pointers to hold onto them and handle all the reference counting issues. The only real way to do this is by overloading all the pointer operators. This doesn''t really work if you initialize them with gcnew. This is certainly not a feature. After deserialization there is no storage associated with the variable and no way to ever use the variable again. You can''t use gcnew with a variable declared with stack semantics.

These smart pointers are essential to our code. I am supposed to release this product in 3 months and now it looks like I am going to have to manually implement ISerializable on a hunderd classes. I will have just made my code base magnitudes more error prone. If I don''t get a work around for this, I am @#


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

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