继承自班级 [英] inherit from class

查看:63
本文介绍了继承自班级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Company的课程。我现在想为一个特定的应用程序制作一个

CompanyEx类,它将继承公司。


所以


类CompanyEx:公司


如何设置基数?在这件事情上有点困惑。


基本上在构造函数中我觉得我会做点什么

public CompanyEx(公司公司)

{

base =公司

}


但这显然不起作用。但现在你可以看到我想要做什么。

请帮忙! :)

I have a class called Company. I now want to make for one particular app a
CompanyEx class, which will inherit from Company.

So

class CompanyEx: Company

how do I set the base? kind of confused on this thing.

basically in the constructor it seems like I would do something like

public CompanyEx(Company company)
{
base = company
}

but that obviously doesn''t work. but now you can see what i''m trying to do.
please help! :)

推荐答案

2007年5月16日星期三15:27:51 -0700,Nathan Laff< re **** **@hotmail.com

写道:
On Wed, 16 May 2007 15:27:51 -0700, Nathan Laff <re******@hotmail.com
wrote:

[...]

如何设置基础?在这件事情上有点困惑。


基本上在构造函数中我觉得我会做点什么

public CompanyEx(公司公司)

{

base =公司

}


但这显然不起作用。但是现在你可以看到我想要的是什么。请帮忙! :)
[...]
how do I set the base? kind of confused on this thing.

basically in the constructor it seems like I would do something like

public CompanyEx(Company company)
{
base = company
}

but that obviously doesn''t work. but now you can see what i''m trying to
do. please help! :)



您可以通过输入:base(< parameter list>)来调用基本构造函数。

构造函数声明后。例如:


public CompanyEx(公司公司):base(company)

{

}


请注意,上面的内容非常具体:它使用现有的Company实例初始化一个新的
CompanyEx实例。为了实现这一点,

你的公司类必须有一个构造函数,它将现有的公司实例作为参数。


重要的是要了解公司继承的新

CompanyEx实例的部分是新的,就像CompanyEx是新的一样。也就是说,您可以使用现有的公司类构造函数将现有公司实例中的内容复制到新的CompanyEx

实例中,并使用现有的

公司实例。但传入的实例与新创建的CompanyEx实例之间不会有任何长期的

关系,除非你写了另外的代码来实现它。特别是,如果你所做的就是将传入的公司实例克隆到新的公司

实例(它本身是新的CompanyEx实例的一部分),然后更改

传入公司实例以后不会更改新公司

实例。


Pete

You can call the base constructor by putting ": base(<parameter list>)"
after the constructor declaration. For example:

public CompanyEx(Company company) : base(company)
{
}

Note that the above does a very specific thing: it initializes a new
CompanyEx instance using an existing Company instance. For that to work,
your Company class must have a constructor that takes as a parameter an
existing Company instance.

It''s important to understand that the Company-inherited parts of the new
CompanyEx instance are new just as the CompanyEx is new. That is, you can
copy stuff from the existing Company instance into the new CompanyEx
instance, using the Company class constructor that takes an existing
Company instance. But the instance passed in will not have any long-term
relationship with the newly created CompanyEx instance unless you write
additional code that would implement that. In particular, if all you''re
doing is cloning the passed-in Company instance into the new Company
instance (itself a part of the new CompanyEx instance), then changing the
passed-in Company instance later isn''t going to change the new Company
instance.

Pete


" Nathan Laff" < re ****** @ hotmail.comwrote in message

news:02 ************************ ********** @ microsof t.com ...
"Nathan Laff" <re******@hotmail.comwrote in message
news:02**********************************@microsof t.com...

>我有一个名为Company的课程。我现在想为一个特定的应用程序制作一个
CompanyEx类,它将继承公司。


所以


类CompanyEx :公司


如何设置基数?在这件事情上有点困惑。


基本上在构造函数中我觉得我会做点什么

public CompanyEx(公司公司)

{

base =公司

}


但这显然不起作用。但是现在你可以看到我想要的是什么。请帮忙! :)
>I have a class called Company. I now want to make for one particular app a
CompanyEx class, which will inherit from Company.

So

class CompanyEx: Company

how do I set the base? kind of confused on this thing.

basically in the constructor it seems like I would do something like

public CompanyEx(Company company)
{
base = company
}

but that obviously doesn''t work. but now you can see what i''m trying to
do. please help! :)



你不能设置基数。如果你有一个现有的公司对象你不能将它变成一个CompanyEx,你必须从

开始创建一个CompanyEx类。

You can''t "set the base". If you have an existing Company object you cannot
turn it into a CompanyEx, you have to create a CompanyEx class from the
start.


>
>





" Nathan Laff" < re ****** @ hotmail.comwrote in message

news:02 ************************ ********** @ microsof t.com ...

"Nathan Laff" <re******@hotmail.comwrote in message
news:02**********************************@microsof t.com...

>我有一个名为Company的课程。我现在想为一个特定的应用程序制作一个
CompanyEx类,它将继承公司。


所以


类CompanyEx :公司


如何设置基数?在这件事情上有点困惑。


基本上在构造函数中我觉得我会做点什么

public CompanyEx(公司公司)

{

base =公司

}


但这显然不起作用。但是现在你可以看到我想要的是什么。请帮忙! :)
>I have a class called Company. I now want to make for one particular app a
CompanyEx class, which will inherit from Company.

So

class CompanyEx: Company

how do I set the base? kind of confused on this thing.

basically in the constructor it seems like I would do something like

public CompanyEx(Company company)
{
base = company
}

but that obviously doesn''t work. but now you can see what i''m trying to
do. please help! :)



这是一个例子。

http://support.microsoft.com/kb/307205

Here is an example.

http://support.microsoft.com/kb/307205


这篇关于继承自班级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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