具体课程 [英] Concrete class

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

问题描述

什么样的类被称为具体类?


什么时候成员函数应该在定义为纯虚拟的类中运行?当

为虚拟时?


谢谢!

解决方案

2004年5月1日星期六20:15:59 GMT,mead < pH值****** @ light.com>写道:

什么样的类被称为具体类?


您可以实例化一个。直。在无处不在的形状中。 class

例子,一个名为Shape的基类然后派生类如

作为Circle,Rectangle等等,有理由说

圈c;

但不是

形状;


(虽然

形状* s

会完美感觉,只要你不尝试:

Shape * s = new Shape;

成员函数何时应该在一个定义为纯的类中运行虚拟和什么时候
作为虚拟?


这实际上与你的第一个问题非常相关。制作方式

a class is abstract是给它至少一个纯虚函数。

如果一个基类包含一个或多个纯虚函数,那么就有两件事情真的发生了两件事。一个是类是抽象的;但是对于

,单独一个纯虚函数就足够了。

另一件事是从类派生出来的基础

类必须实现/每个/他们继承的纯虚函数

才能成为具体的类。因此,如果派生类只有

实现了它继承的8个纯虚函数中的7个,那么它仍然是一个抽象类。但是进一步派生类只会继承单个纯虚函数,而进一步派生类将通过实现一个函数来实现具体化。

-leor

谢谢!




Leor Zolman< le ** @ bdsoft.com>在消息中写道

news:tf ******************************** @ 4ax.com ...

2004年5月1日星期六20:15:59 GMT,mead < pH值****** @ light.com>写道:

什么样的类被认定为具体类?



您可以实例化。直。在无处不在的形状中。 class
例如,一个名为Shape的基类然后派生类如
如Circle,Rectangle等,有意义地说
Circle c;
但不是
Shape s;

(虽然
Shape * s
会很有意义,只要你不尝试:
Shape * s = new Shape;


如果Shape具有纯虚函数并且此函数在

Circle类中实现派生,那么Circle将成为一个可以成为的类

实例化,因此Circle是具体类,但Shape不是。它是否正确?


如果Shape没有纯虚函数而是虚函数(s) ),它是一个

的具体类吗?

当一个成员函数定义为纯虚拟和
时虚拟?



这实际上与你的第一个问题非常相关。使一个类成为抽象类的方法是给它至少一个纯粹的virt ual函数。
如果一个基类包含一个或多个纯虚函数,那么真的有两件事情正在发生。一个是班级是抽象的;但是对于
而言,单个纯虚函数就足够了。
另一件事是从基类派生的类必须实现/每个/纯虚拟他们继承的职能是为了具备作为具体阶级的资格。因此,如果派生类仅实现其继承的8个纯虚函数中的7个,那么它仍然是一个抽象类。但是进一步派生类只会继承单个纯虚函数,而进一步派生类将通过实现一个函数而变得具体。
-leor




定义纯虚函数和定义虚拟函数时

在类中?


" mead" ; < pH值****** @ light.com>写道...

Leor Zolman< le ** @ bdsoft.com>在消息中写道
新闻:tf ******************************** @ 4ax.com ... < blockquote class =post_quotes> 2004年5月1日星期六20:15:59 GMT,mead < pH值****** @ light.com>写道:

什么样的类被称为具体类?
您可以实例化。直。在无处不在的形状中。 class
例如,一个名为Shape的基类然后派生类如
如Circle,Rectangle等,有意义地说
Circle c;
但不是
Shape s;

(虽然
Shape * s
会很有意义,只要你不尝试:
Shape * s = new Shape;


如果Shape具有纯虚函数,并且此函数在
Circle类中实现为派生,则Circle变为可以实例化的类,因此Circle是具体的类但是Shape不是。是



是否正确?


是的。

如果Shape没有纯虚函数而是虚函数,那么它是
a具体类吗?


虚拟这一事实函数都是定义的(不是纯粹的)基本上

表示该类具有特定的行为。这通常意味着

该类是具体的。

[..]
定义时一个纯虚函数,在一个类中定义一个虚函数时?




我不确定我是否理解这个问题(这不是一个合适的问题)英语

句子),但是,通常,你定义一个虚拟函数纯粹只有在

它没有意义(或不可能)指定任何具体的

的定义。采用相同的Shape vs Circle示例Leor给出了

并尝试声明/定义成员函数''getArea''。我总是

相信这样做是比听取或阅读解释更好的理解方式。


Victor


What kind of classes is qualified as "concrete classes"?

When should a member function in a class defined as "pure virtual" and when
as "virtual"?

Thanks!

解决方案

On Sat, 01 May 2004 20:15:59 GMT, "mead" <ph******@light.com> wrote:

What kind of classes is qualified as "concrete classes"?
One you can instantiate. directly. In the ubiquitous "Shape" class
example, with a base class named "Shape" and then derived classes such
as "Circle", "Rectangle", etc., it makes sense to say
Circle c;
but not
Shape s;

(Although
Shape *s
would make perfect sense, as long as you don''t try to do:
Shape *s = new Shape;

When should a member function in a class defined as "pure virtual" and when
as "virtual"?
That''s actually quite related to your first question. The way to make
a class be abstract is to give it at least one pure virtual function.
If a base class contains one or more pure virtual functions, there are
really two things going on. One is that the class is abstract; but for
that alone, a single pure virtual function would have been sufficient.
The other thing going on is that classes which derive from the base
class must implement /each/ of the pure virtual functions they inherit
in order to qualify as a concrete class. So if a derived class only
implements 7 out of 8 of the pure virtual functions it inherits, it is
still an abstract class. But a further derived class will inherit only
a single pure virtual function, and that further derived class would
become concrete by implementing that one function.
-leor

Thanks!




Leor Zolman <le**@bdsoft.com> wrote in message
news:tf********************************@4ax.com...

On Sat, 01 May 2004 20:15:59 GMT, "mead" <ph******@light.com> wrote:

What kind of classes is qualified as "concrete classes"?



One you can instantiate. directly. In the ubiquitous "Shape" class
example, with a base class named "Shape" and then derived classes such
as "Circle", "Rectangle", etc., it makes sense to say
Circle c;
but not
Shape s;

(Although
Shape *s
would make perfect sense, as long as you don''t try to do:
Shape *s = new Shape;

If "Shape" has a pure virtual function and this function is implemented in
Circle class as derived, then Circle becomes a class that can be
instantiate, thus Circle is concrete class but Shape isn''t. Is it correct?

If Shape has no pure virtual function but virtual function(s), will it be a
concrete class?

When should a member function in a class defined as "pure virtual" and whenas "virtual"?



That''s actually quite related to your first question. The way to make
a class be abstract is to give it at least one pure virtual function.
If a base class contains one or more pure virtual functions, there are
really two things going on. One is that the class is abstract; but for
that alone, a single pure virtual function would have been sufficient.
The other thing going on is that classes which derive from the base
class must implement /each/ of the pure virtual functions they inherit
in order to qualify as a concrete class. So if a derived class only
implements 7 out of 8 of the pure virtual functions it inherits, it is
still an abstract class. But a further derived class will inherit only
a single pure virtual function, and that further derived class would
become concrete by implementing that one function.
-leor



When defining a pure virtual function and when defining a virtual function
in a class?


"mead" <ph******@light.com> wrote...

Leor Zolman <le**@bdsoft.com> wrote in message
news:tf********************************@4ax.com...

On Sat, 01 May 2004 20:15:59 GMT, "mead" <ph******@light.com> wrote:

What kind of classes is qualified as "concrete classes"?
One you can instantiate. directly. In the ubiquitous "Shape" class
example, with a base class named "Shape" and then derived classes such
as "Circle", "Rectangle", etc., it makes sense to say
Circle c;
but not
Shape s;

(Although
Shape *s
would make perfect sense, as long as you don''t try to do:
Shape *s = new Shape;


If "Shape" has a pure virtual function and this function is implemented in
Circle class as derived, then Circle becomes a class that can be
instantiate, thus Circle is concrete class but Shape isn''t. Is it


correct?

Yes.
If Shape has no pure virtual function but virtual function(s), will it be a concrete class?
The fact that virtual functions are all defined (not pure) basically
indicates that the class has specific behaviour. That usually means
that the class is concrete.
[..]
When defining a pure virtual function and when defining a virtual function
in a class?



I am not sure I understand the question (it''s not a proper English
sentence), but, usually, you define a virtual function pure only if
it doesn''t make sense (or is impossible) to specify any concrete
definition for it. Take the same Shape vs Circle example Leor gave
and try to declare/define the member function ''getArea''. I always
was a believer that doing it is much better way to understand than
listening to or reading an explanation.

Victor


这篇关于具体课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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