24小时热门版块排行榜    

查看: 685  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见