问题标签 [derived-types]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 如何控制什么可以和什么不能在程序集之外导出?
假设我有一个基类B
,它必须从程序集中导出。有两个类,D1
并且D2
派生自B
,我希望它们是唯一派生自它的类。我的目标是:
- 使
B
组件外可见; - 禁止派生或实例化
B
; - 导出
D1
和D2
禁止从它们派生。
做什么的?比方说,我需要外部类提供一个B
s 列表,它只能由D1
s 或D2
s 组成。
我该怎么做?
pointers - Fortran 派生类型 - 指向私有数组的公共指针
我正在尝试定义具有私有可分配数组的 Fortran 派生类型。但是,我希望能够通过公共指针访问该数组以在其他模块中使用。例如
像上面那样尝试它时,我只是得到一个编译器错误。
如果不编写指向我的子程序,这是否可能?
fortran - 在多态派生类型中使用私有语句的 gfortran v4.9 错误
在用于形成多态对象的派生类型类中使用 private 语句时,gfortran v4.9.0 编译器出现编译器错误。相反,ifort v14.0.2 确实成功编译了此代码,并且可执行文件运行没有错误。下面的示例源代码导致来自 gfortran 的以下错误消息:
ch2605.poly.f90:58.2:
s %x = shape_type(3)
1
错误:尚不支持在 (1) 处分配给可分配多态变量
如果 private 语句被注释掉并且整个 shape_module 属性/方法被公开,那么 gfortran 编译代码成功。我的两个问题是:
1) 在这种情况下,上面的 gfortran 错误消息是否正确?
2) 在尝试将基派生类型 shape_type 的内容设为私有时,我应该做些什么不同的事情?
注意:我已经从 fortranplus 网站上的 ch2605_2.f90 改编了这个示例源代码。
module - 在单独的模块中扩展派生类型而不更改类型的名称
我可以通过添加一个模块文件来扩展程序,在该文件中我扩展最初定义的派生类型,例如:
但是使用这个解决方案,每次添加另一个模块时,我都需要在调用程序中更改“a”(type1->type2)的声明。所以我的问题是是否有办法解决这个问题,即我可以将类型绑定过程添加到另一个模块中的派生类型,而无需更改类型的原始名称。
我完全理解这可能行不通,因为我可以稍后声明一个变量并扩展它的类型,这对我来说听起来有问题。所以,我想到了延期声明。但这并不是我真正想要的,因为我首先必须将它添加到原始定义中,其次我需要提供一个接口,因此需要知道后面的函数(这里是 g)的变量。但是,也许有人对此有一个很好的解决方案。
所有这些当然是为了给程序带来更多的结构,尤其是当我想到不同的人同时在一个程序上工作时,这种拆分工作包的可能性似乎相当有用。
fortran - 类型绑定过程作为参数
我想将类型绑定过程(作为外部函数)传递给另一个函数,如下所示:
gfortran 产生了这个错误:
但我能做的是:
我认为这个问题与将类型绑定过程作为参数传递有关,但我目前看不到那里的答案对我有什么帮助。
编辑:
一个更好的例子(希望)显示了困难:
编辑二:好的,包装器仍然与指针结合使用:
这当然不是一个漂亮的解决方案,但至少它有效。
gdb - Fortran:派生类型的可分配数组包含派生类型的数组
我目前正在开发一个大型 Fortran 程序,其中我有一个离散的数值网格,其中包含我在网格范围内跟踪的一系列粒子。为此,我定义了以下三种派生类型:
首先,这是对派生类型的可接受使用(即,具有包含派生类型数组的派生类型的可分配数组)?该代码使用 gfortran 4.8.3 编译得很好。
但是,在 Fedora 下尝试使用 gdb 7.7.1 调试代码时,我遇到了一些奇怪的问题。当试图查看rbin
数组元素中的数据时(例如使用),即使我已将数据分配给(例如) print rbin(10)%bpoints
,gdb 总是会打印出来。如果我使用例如查看数组元素中的数据,那么我得到的正是我所期望的。有人对这个问题有一些见解吗?(0, 0, 0, 0, 0, 0)
bpoints
rbin(10)%bpoints = (/1,2,1,2,1,2/)
pbin
print pbin(10)%bpoints
fortran - Fortran 派生类型:重载赋值运算符不适用于“参数”属性
我正在使用派生类型(bicomplex)和赋值运算符(=)的重载,以便可以将 a 分配real*8
给bicomplex
. bicplx 模块的 MWE 如下:
实数到复数的分配由 Fortran 本质上处理。此方法在“典型”双复变量上使用时效果很好,但是当我想将 a 分配给real*8
具有以下PARAMETER
属性的双复时会中断:
完美运行,但是:
不编译并给出 2 个错误:Error: Incompatible derived type in PARAMETER at (1)
和Error: Can't convert REAL(8) to TYPE(bicomplex) at (1)
. 然而,
完美运行。
是否有我遗漏的东西,或者它是标准的一部分,不能通过使用重载赋值运算符来分配参数?理想情况下,我想使用 F90/F95(而不是 2003 或 2008)来解决这个问题。
c# - 这种“模式”可以吗还是有更好的方法?
我的应用程序中有几个类(只是一个片段):
当我知道变量补丁是子类型程序时,我使用:
或更好:
当我不知道它是否是一个程序时:
但是,我的代码(将)充满了这些结构。有没有更好的方法来实现这一点?
例子:
protobuf-net - protobuf-net 中的派生是如何工作的?
就像我在 C# 中所做的那样:
有没有办法用原始文件中的消息重新创建这种行为?这样DerivedClass
is 的类型BaseClass
并且可以继承它的属性。
我尝试了extend
我的基本信息,但这会产生不同的结果。
xml - Creating and using derived types in XML schema
Edited in order to make a complete schema that can be tested if needed as suggested in the comments below
Let's say I have a small XML schema defined as follows:
The type gradeType is being used to determine how the value of the grade element restricted and how it is to be evaluated. What I want to do is use the specified above simple and complex types as two derivatives of gradeType. The simple type of grade allows me to use only a limited set of choices due to a restriction in the grading scale. The complex type on the other hand allows me basically an unlimited interval between 1.0 and 5.0 since I use it to compute the arithmetic mean of multiple simple grades and round it to the closest simple grade available in an XSLT. However I have no idea how to change my gradeType in such a way so that both simple types simple and complex can be used when I create a grade element. I have read about deriving types (here: simple,complex) from a base class (here: gradeType) but it seems I simply don't get it.
Example how I imagine grade should look like:
Edit As suggested below the xs:union element was tested:
This leads to following two errors in all grade elements in my XML document:
cvc-datatype-valid.1.2.3: 'simple' is not a valid value of union type 'gradeType'.
cvc-attribute.3: The value 'simple' of attribute 'type' on element 'grade' is not valid with respect to its type, 'gradeType'.
Edit 2: As noted by @lexicore I have it more or less all wrong or probably just explained badly. I will try to use pseudo-code to describe how the grade element is supposed to work: