- UID
 - 3599
 - 性别
 - 保密
 
  
齊天大聖 
- 积分
 - 779
 
  F 币- 434 元
 
- 最后登录
 - 2025-7-31
 
  贡献- 266 点
 
- 注册时间
 - 2018-11-8
 
  权杖- 0 枚
 
惯用编译器:GFortran / G77 for Linux
 
 
 
 
  
专家 
齊天大聖 
    F 币- 434 元
 
    贡献- 266 点
 
 
 
 
 | 
 
 本帖最后由 lookbook 于 2018-12-1 15:54 编辑  
 
父类如下: 
 
...                                                                  |      ...  
                                                                     | 
type,abstract :: t_a                                         |      type,abstract :: t_a 
   integer :: a                                                 |         integer:: a 
contains                                                        |      contains 
   procedure(fun1),pass(this),deferred :: fun1   |         procedure(fun1_mode),pass(this),deferred :: fun1 
end type                                                        |      end type 
                                                                    |  
abstract interface                                           |     abstract interface 
   module subroutine fun1(this)                        |        module subroutine fun1_mode(this) 
   class(t_a)::this                                            |        class(t_a)::this  
   ...                                                              |        ... 
   end subroutine                                            |        end subroutine 
end interface                                                 |     end interface  
                                                                    | 
private fun1                                                   | 
end                                                              |      end   
 
 
子类: 
use ... 
type,extends(t_a)::t_b 
real :: b 
contains 
procedure,pass(this) :: fun1 
end type 
 
 
contains 
 
subroutine fun1(this) 
class(t_b) :: this 
... 
end subroutine 
... 
 
------------------------------------------------------ 
这两种形式我都试过可以,第一种deferred的过程可以和接口名称一样,但必须加private 
第二种就是书上的 
 
其实我一直有个问题,过程名可以和接口名一致吗? 
第一种方法会造成诸如扩展维护上的问题吗? 
 
 
 |   
 
 
 
 |