24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 736  |  回复: 6

Jeydragon

木虫 (正式写手)

[交流] 【求助】有错误 已有3人参与

Program Summation
Implicit None
Interface My_Sum
        Function Sum_Real(A,B) Result(Sum_Real_Result)
                Real :: A,B, Sum_Real_Result
        End Function Sum_Real

        Function Sum_Integer(A,B) Result(Sum_Integer_Result)
                Integer :: A,B, Sum_Integer_Result
        End Function Sum_Integer
End Interface
Real ::X,Y
Integer :: I,J
Read *,X,Y,I,J
print *, My_Sum(X,Y), My_Sum(I,J)
contains
        Function Sum_Real(A,B) Result(Sum_Real_Result)
                Real :: A,B,Sum_Real_Result


                Sum_Real_Result=A+B
        End Function Sum_Real

        Function Sum_Integer(A,B) Result(Sum_Integer_Result)
                Integer :: A,B,Sum_Integer_Result
                Sum_Integer_Result=A+B
        End Function Sum_Integer
End Program Summation


运行出错,怎么回事?请指教
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

欲海沉浮名利争,石光电火步此生;风尘情事挥不尽,观世不笑是痴人。
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

maomao1210

金虫 (正式写手)

★ ★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
余泽成(金币+2):谢谢参与应助! 2010-12-20 20:24:40
引用回帖:
Originally posted by Jeydragon at 2010-12-20 09:24:36:
Program Summation
Implicit None
Interface My_Sum
        Function Sum_Real(A,B) Result(Sum_Real_Result)
                Real :: A,B, Sum_Real_Result
        End Function Sum_Real

        Function Sum_Integer(A,B) Result(Su ...


你用的是OVERLOAD功能,而不是接口参数和返回类型说明吧。
把interface 中的修改为图片这样就可以了。
2楼2010-12-20 14:37:20
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

Jeydragon

木虫 (正式写手)

还是有问题。。。

Error: The name of the internal procedure conflicts with a name in the encompassing scoping unit.   [SUM_REAL]
Function Sum_Real(A,B) Result(Sum_Real_Result)

Error: The name of the internal procedure conflicts with a name in the encompassing scoping unit.   [SUM_INTEGER]
Function Sum_Integer(A,B) Result(Sum_Integer_Result)

Error: There is no matching specific function for this generic function reference.   [MY_SUM]
print *, My_Sum(X,Y), My_Sum(I,J)
。。。。。。
欲海沉浮名利争,石光电火步此生;风尘情事挥不尽,观世不笑是痴人。
3楼2010-12-20 16:59:22
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

Jeydragon

木虫 (正式写手)

类属函数
欲海沉浮名利争,石光电火步此生;风尘情事挥不尽,观世不笑是痴人。
4楼2010-12-20 17:07:44
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

★ ★ ★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
余泽成(金币+3):谢谢参与应助! 2010-12-21 11:01:51
你想要是这样的效果吗?
CODE:
module swap_module
   implicit none
   public :: swap
   private :: swap_reals, swap_integers
   interface swap
      module procedure swap_reals, swap_integers
   end interface
   contains
   subroutine swap_reals(a, b)
   real, intent(in out) :: a, b
   real :: temp
   temp = a
   a = b
   b = temp
   end subroutine swap_reals
   subroutine swap_integers(a, b)
   integer, intent(in out) :: a, b
   integer :: temp
   temp = a
   a = b
   b = temp
   end subroutine swap_integers
end module swap_module

program test_swap
use swap_module
implicit none
real :: x, y
integer :: i, j
x = 1.1
y = 2.2
i = 1
j = 2
call swap(x, y)
print *, x, y
call swap(i, j)
print *, i, j
end program test_swap

5楼2010-12-20 20:22:39
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

Jeydragon

木虫 (正式写手)

1、首先感谢你的回复,辛苦了。
2、我是想通过My_Sum,将整数和实数相加这两个函数合并在一起,调用的时候,在这里只需要My_Sum即可而不需要Sum_Integer和Sum_Real。我这个例子也是看到书上这么写的,我就是运行不成功。。。
欲海沉浮名利争,石光电火步此生;风尘情事挥不尽,观世不笑是痴人。
6楼2010-12-20 22:05:10
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)


小木虫(金币+0.5):给个红包,谢谢回帖交流
引用回帖:
Originally posted by Jeydragon at 2010-12-20 22:05:10:
1、首先感谢你的回复,辛苦了。
2、我是想通过My_Sum,将整数和实数相加这两个函数合并在一起,调用的时候,在这里只需要My_Sum即可而不需要Sum_Integer和Sum_Real。我这个例子也是看到书上这么写的,我就是运行 ...

你看了我给的代码了吗?不就是你所说的这个功能吗?swap 两个数值时,只需要 swap,不需要 swap_integers 和 swap_reals 啊……
7楼2010-12-21 09:23:44
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 Jeydragon 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 一志愿华东理工085601材料工程303分求调剂 +6 a1708 2026-04-06 6/300 2026-04-06 22:37 by guanxin1001
[考研] 085600材料与化工专硕329 求调剂 +11 额cc 2026-04-06 11/550 2026-04-06 22:33 by chenzhimin
[考研] 求调剂 +5 熊二想上岸 2026-04-06 5/250 2026-04-06 22:27 by chenzhimin
[考研] 生物学求调剂 一志愿沪9,326分 +6 刘墨墨 2026-04-06 6/300 2026-04-06 19:36 by lijunpoly
[考研] 0857大类环境工程B区求调剂 +3 龚禹铭 2026-04-05 3/150 2026-04-06 10:22 by 蓝云思雨
[考研] 377求调剂 +6 by.ovo 2026-04-05 6/300 2026-04-05 22:18 by dongzh2009
[考研] 322求调剂 +3 嗯哼哼恒 2026-04-05 3/150 2026-04-05 19:52 by nepu_uu
[考研] 298分 070300求调剂 +15 zwen03 2026-04-02 15/750 2026-04-05 12:52 by Hdyxbekcb
[考研] 359求调剂22408 +3 123456789qw 2026-03-31 3/150 2026-04-05 10:09 by zhq0425
[考研] 一志愿北京化工大学,初试成绩350求调剂 +9 沿岸?贝壳 2026-04-04 14/700 2026-04-05 01:09 by 沿岸?贝壳
[考研] 材料295 +13 小英11 2026-04-03 14/700 2026-04-04 09:02 by 来看流星雨10
[考研] 265求调剂 +20 梁梁校校 2026-04-01 21/1050 2026-04-04 00:38 by userper
[考研] 313求调剂 +3 ~微微凉~ 2026-04-03 3/150 2026-04-03 11:25 by 啵啵啵0119
[考研] 专硕 351 086100 也是考的材科基 本科也是材料 +8 202451007219 2026-04-02 8/400 2026-04-03 09:50 by 蓝云思雨
[考研] 348求调剂 +11 zzzzyk123 2026-04-01 11/550 2026-04-02 16:52 by Wang200018
[考研] 学硕化学工程与技术,一志愿中国海洋大学320+求调剂 +8 披星河 2026-04-02 8/400 2026-04-02 14:12 by oooqiao
[考研] 298求B区调剂 +4 zzz,,r 2026-04-02 5/250 2026-04-02 12:17 by 土木硕士招生
[考研] 292求调剂 +17 木虫er12138 2026-04-01 17/850 2026-04-01 21:37 by 七度不信任
[考研] 349求调剂 +6 吃的不少 2026-04-01 6/300 2026-04-01 17:55 by JYD2011
[考研] 318求调剂 +8 七忆77 2026-04-01 8/400 2026-04-01 10:37 by Jaylen.
信息提示
请填处理意见