fortran 2003 中类型和类的区别 [英] Difference between type and class in fortran 2003

查看:20
本文介绍了fortran 2003 中类型和类的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在攻读博士学位时,有人告诉我必须学习 fortran 2003 语言.我以前从未使用过 OOP 程序,也没有使用过 fortran.我试图了解类型和类之间的区别是什么.我知道类是用'TYPE'关键字声明的,但我也看到使用关键字'CLASS'的例子,所以我很困惑.希望这是有道理的.

I have been told for my PhD that I have to learn fortran 2003 language. I have never used and OOP program before nor fortran. I am trying to understand what the difference between type and class is. I know that classes are declared with the 'TYPE' keyword but I have also seen examples of the keyword 'CLASS' being used used so I am getting confused. Hope that makes sense.

推荐答案

关键字type用来声明派生类型 -- 最好不要养成思考,也许是从外语导入的,type 用于声明称为 classes 的东西.

The keyword type is used to declare derived types -- best not to get into the habit of thinking, perhaps imported from foreign languages, that type is used for declaring something called classes.

关键字class 在受限情况下用于表示指定类型或其任何扩展类型.extended type 是 Fortran 语言,表示扩展另一种类型的类型,本质上是一种 专门化 继承另一种类型的类型.使用 class 的受限情况是在过程虚拟参数列表中以及在具有属性 allocatable 或属性 pointer 的实体声明中.class 实体在运行时获得动态 type,其动态类型可能因运行而异,或在程序的单次执行中不同.

The keyword class is used, in restricted circumstances, to mean of the type specified or any of its extended types. extended type is Fortran-speak for a type which extends another type, essentially one which specialises or inherits from another type. The restricted circumstances within which class is used are in procedure dummy-argument lists and in declarations of entities with the attribute allocatable or the attribute pointer. A class entity gets a dynamic type at run-time, and its dynamic type may vary from run to run, or across a single execution of the program.

如果您不理解前面段落中的解释,可能是因为我解释得不好,但也可能是因为您还没有足够的 Fortran 基础知识.要获得基础知识,请查找最新的在线教程、在线参考指南,然后开始编程.

If you don't understand the explanation in the previous paragraphs it's possibly because I've explained things poorly, but it's also possibly because you don't yet have enough of a grounding in the basics of Fortran. To acquire the grounding find yourself an up-to-date online tutorial, an online reference guide, and start programming.

这篇关于fortran 2003 中类型和类的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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