Ctype fire默认构造函数? [英] Ctype fire default contructor?

查看:57
本文介绍了Ctype fire默认构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我试图将一个物体投射到它的一个后代上,那么

后代的默认构造函数(New sub)会被点燃吗?


谢谢,


Craig

解决方案

我不这么认为......这会导致分配内存并将

父对象复制到decendent对象。这看起来很浪费......然后再次,

我知道什么。 =)


我会导致没有......但有人会告诉我,我错了。


Craig布坎南" <所以***** @ microsoft.com>在消息中写道

新闻:uw ************* @ TK2MSFTNGP09.phx.gbl ...

如果我正在尝试演员它的一个后代的一个对象,
后代的默认构造函数(New sub)会消防吗?

谢谢,

Craig



" Craig Buchanan" <所以***** @ microsoft.com> schrieb

如果我试图将一个对象强制转换为其后代之一,那么后代的默认构造函数(New sub)会被激活吗?




如果你/ cast /一个对象:没有。 Casting不会创建一个新对象,它只会改变引用的类型
。如在主题中所提到的,CType可以同时执行两个(与仅投射的Directcast相反):转换和转换(通常

混合)。如果CType创建一个新对象,是的,构造函数将被调用
。如果CType只投射:没有新实例 - >没有构造函数叫

-

Armin


如何报价及原因:
http://www.plig.net/nnq/nquote.html
< a rel =nofollowhref =http://www.netmeister.org/news/learn2quote.html\"target =_ blank> http://www.netmeister.org/news/learn2quote.html


好吧,我不明白...


Ctype如何调用构造函数?如果没有无争议的

构造函数怎么办?在调用构造函数时,旧分配的内存会发生什么?那个对象刚丢失并被GC清理了吗?


对不起所有的问题Armin,我只是不明白它是如何工作的。


-CJ

" Armin Zingler" < AZ ******* @ freenet.de>在消息中写道

news:40 *********************** @ news.freenet.de ...

Craig Buchanan <所以***** @ microsoft.com> schrieb

如果我试图将一个物体投射到它的一个后代上,那么后代的默认构造函数(New sub)会不会消防?
如果你/ cast / an对象:没有。 Casting不会创建新对象,它只会更改引用的类型。如在主题中所提到的,CType可以同时执行两者(与仅直接投射相反的投射):投射和转换



(经常混淆)。如果CType创建一个新对象,是的,将调用构造函数。如果CType只投射:没有新实例 - >没有构造函数叫

-
Armin

如何引用和原因:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html



If I am trying to cast an object to one of its decendants, will the
decendants'' default constructor (New sub) fire?

Thanks,

Craig

解决方案

I don''t think so...that would result in allocating memory and copying the
parent object to the decendent object. which seems wasteful... then again,
what do I know. =)

I would lead to no... but someone will tell me I''m wrong in aminute.

"Craig Buchanan" <so*****@microsoft.com> wrote in message
news:uw*************@TK2MSFTNGP09.phx.gbl...

If I am trying to cast an object to one of its decendants, will the
decendants'' default constructor (New sub) fire?

Thanks,

Craig



"Craig Buchanan" <so*****@microsoft.com> schrieb

If I am trying to cast an object to one of its decendants, will
the decendants'' default constructor (New sub) fire?



If you /cast/ an object: no. Casting does not create a new object, it only
changes the type of the reference. CType, as mentioned in the subject, can
do both (in opposite to Directcast that only casts): cast and convert (often
mixed up). If CType creates a new object, yes, the constructor will be
called. If CType only casts: no new instance -> no constructor called
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Alright, I don''t understand that...

How does Ctype call the constructor? What if there is no argumentless
constructor? When calling the constructor what happens to the old allocated
memory? is that object just lost and cleaned up by GC?

Sorry for all the questions Armin, I just dont understand how it works.

-CJ
"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...

"Craig Buchanan" <so*****@microsoft.com> schrieb

If I am trying to cast an object to one of its decendants, will
the decendants'' default constructor (New sub) fire?
If you /cast/ an object: no. Casting does not create a new object, it only
changes the type of the reference. CType, as mentioned in the subject, can
do both (in opposite to Directcast that only casts): cast and convert


(often mixed up). If CType creates a new object, yes, the constructor will be
called. If CType only casts: no new instance -> no constructor called
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html



这篇关于Ctype fire默认构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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