简单继承 - 类型'System.StackOverflowException'的未处理异常... [英] Simple Inheritance - An unhandled exception of type 'System.StackOverflowException'...

查看:54
本文介绍了简单继承 - 类型'System.StackOverflowException'的未处理异常...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好吧


由于我对OOP的探险采取了另一个不稳定的步骤,我现在得到

错误:


发生了'System.StackOverflowException'类型的未处理异常
xxx.dll中的



在我的Visit.cls中我有:


公共课参观

{

public FABInfo Info = new FABInfo(); //错误

标记的行。

}

然后在我的FABInfo.cls中我得到了:


公共密封类FABInfo:访问

{

公共字符串myFunc()

{

return" this.m_sFABSessionID.ToString();" ;;

}

}


当我创建一个访问实例,我得到一个循环

oVisit.Info.Info.Info.Info .....这就是问题所在。


有什么想法吗?


非常感谢


Darren

Hi everyone

As my expedition into OOP takes another shaky step, I now am getting
the error:

An unhandled exception of type ''System.StackOverflowException'' occurred
in xxx.dll.

In my Visit.cls I have got:

public class Visit
{
public FABInfo Info = new FABInfo(); // Line that the error
flags up on.
}
Then in my FABInfo.cls I have got:

public sealed class FABInfo : Visit
{
public string myFunc()
{
return "this.m_sFABSessionID.ToString();";
}
}

When I create an Instance of Visit, I get a loop of
oVisit.Info.Info.Info.Info..... so that is where the problem lies.

Any ideas anyone?

Many thanks

Darren

推荐答案

你创建一个新的访问,并在ctor中创建一个FABInfo ...


*但是*,FABInfo *是*访问,所以这也是运行访问ctor,因此

循环。


这是什么代表?而不是试图修复狡猾的代码,

如果你解释你认为你想做什么,那么人们可以告诉你

正确的做法.. 。这可能与你的代码不太相似; -p


Marc
You create a new Visit, and in the ctor it creates a FABInfo...

*however*, FABInfo *is* a Visit, so this also runs the Visit ctor, and hence
the loop.

What is this trying to represent? Rather than trying to fix the dodgy code,
if you explain what you think you are trying to do, then people can tell you
the right way to do it... which might not resemble your code much ;-p

Marc


嘿Mark - 感谢您的快速回复。 />

访问将成为我的基类,并且它将具有其中的属性

,例如Web服务的位置,用户名,密码等

等。从那里,会有一些儿童课程,如

信息,包裹,细节。


我想要什么要做的是来自Info:Visit,能够访问this.Password

例如和我的其他子课程相同。


这是否有意义?


谢谢


Daz

Hey Mark - thanks for the quick reply.

Visit is going to be my base class, and it will maily have properties
in it such as the location of web services, usernames, passwords etc
etc. And from that, there will be a number of child classes such as
Info, Package, Detail.

What I want to do is from Info:Visit, be able to access this.Password
for example and the same from my other child classes.

Does that make sense?

Thanks

Daz


好的,如果我了解你的场景,然后在访问

ctor中创建的FABInfo是错误的 - 只是抛弃它。如果你想要一个FABInfo,那么只需使用

" new FABInfo()" ...因为FABInfo派生自Visit,这将首先创建新的
FABInfo对象运行访问ctor,然后是FABInfo ctor。


如果访问真的需要一个FABInfo,那么对象模型就会变得棘手;

它是'鸡和鸡蛋:你没有先成功创造一次访问

创建一个FABInfo,而一个FABInfo /是一个访问 - 所以都不能创建。


Marc
OK, if I understand your scenario, then the FABInfo creation in the Visit
ctor is erroneous - just ditch it. If you want a FABInfo, then simply use
"new FABInfo()"... since FABInfo derives from Visit this will create the new
FABInfo object by first running the visit ctor, then the FABInfo ctor.

If the Visit genuinely needs a FABInfo, then the object model is screwy;
it''s chicken and egg: you can''t create a Visit without first successfully
creating a FABInfo, yet a FABInfo /is/ a Visit - so neither can be created.

Marc


这篇关于简单继承 - 类型'System.StackOverflowException'的未处理异常...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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