24小时热门版块排行榜    

查看: 728  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 药学383 求调剂 +3 药学chy 2026-03-15 4/200 2026-03-16 20:51 by 元子^0^
[考研] 0854控制工程 359求调剂 可跨专业 +3 626776879 2026-03-14 9/450 2026-03-16 17:42 by 626776879
[考研] 070303 总分349求调剂 +3 LJY9966 2026-03-15 5/250 2026-03-16 14:24 by xwxstudy
[考研] 304求调剂 +6 小熊joy 2026-03-14 6/300 2026-03-16 12:59 by Iveryant
[考研] 255求调剂 +3 李嘉慧, 2026-03-12 4/200 2026-03-14 16:58 by 有只狸奴
[考研] 328求调剂 +3 5201314Lsy! 2026-03-13 6/300 2026-03-14 15:31 by hyswxzs
[考研] 材料与化工(0856)304求B区调剂 +7 邱gl 2026-03-10 11/550 2026-03-14 12:18 by 邱gl
[考研] 297求调剂 +4 学海漂泊 2026-03-13 4/200 2026-03-14 11:51 by 热情沙漠
[考研] 330求调剂 +3 ?酱给调剂跪了 2026-03-13 3/150 2026-03-14 10:13 by JourneyLucky
[考研] 271求调剂 +10 生如夏花… 2026-03-11 10/500 2026-03-14 00:35 by 卖报员小雨
[考研] 材料工程,326分,求调剂 +6 KRSLSR 2026-03-10 6/300 2026-03-13 23:47 by JourneyLucky
[考研] 341求调剂 +4 番茄头--- 2026-03-10 4/200 2026-03-13 23:12 by JourneyLucky
[考研] 285 求调剂 资源与环境 一志愿北京化工大学 +3 未名考生 2026-03-10 3/150 2026-03-13 23:04 by JourneyLucky
[考研] 求材料调剂 085600英一数二总分302 前三科235 精通机器学习 一志愿哈工大 +4 林yaxin 2026-03-12 4/200 2026-03-13 22:04 by 星空星月
[考研] 工科材料085601 279求调剂 +8 困于星晨 2026-03-12 10/500 2026-03-13 15:42 by ms629
[考研] 土木第一志愿276求调剂,科研和技能十分丰富,求新兴方向的导师收留 +3 土木小天才 2026-03-12 3/150 2026-03-13 15:01 by JourneyLucky
[考研] 289求调剂 +3 李政莹 2026-03-12 3/150 2026-03-13 11:02 by 求调剂zz
[考研] 工科0856专硕化学工程269能调剂吗 +10 我想读研11 2026-03-10 10/500 2026-03-13 10:14 by Yuyi.
[考研] 一志愿河海大学085900土木水利专硕279求调剂不挑专业 +4 SunWwWwWw 2026-03-10 8/400 2026-03-13 02:23 by SunWwWwWw
[考研] 290求调剂 +3 柯淮然 2026-03-10 8/400 2026-03-11 13:48 by 柯淮然
信息提示
请填处理意见