函数没有隐式类型 [英] Function has no implicit type

查看:193
本文介绍了函数没有隐式类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图学习如何使用函数。我有以下代码:

 程序主
隐含无

写(* *)test(4)
结束程序

整数函数test(n)
隐式无
整数,意图(in):: n
整数:: i,ans

ans = 1
do i = 1,n
ans = ans * i
enddo

test = ans
end function test

当我编译时(使用gfortran 4.1.2)以下错误:

 在文件test.f90中:4 

写(*,*)测试(4)
1
错误:函数'test'at(1)没有IMPLICIT类型


解决方案

移动行

 结束程序

code>

添加到您的源文件的末尾,并在其位置写下行

 包含

在编写程序时不知道函数 test ,哪个是编译器告诉你的。我已经提出了其中一种方法,可以为程序提供所需的知识,但也有其他方法。既然你是一个学习者,我会留给你弄清楚详细情况。


I am trying to learn to work with functions. I have the following code:

program main
  implicit none

  write(*,*) test(4)
end program

integer function test(n)
  implicit none
  integer, intent(in) :: n
  integer :: i, ans

  ans=1
  do i=1,n
  ans=ans*i
  enddo

  test=ans
end function test

When I compile (with gfortran 4.1.2), I get the following error:

In file test.f90:4

  write(*,*) test(4)
           1
Error: Function 'test' at (1) has no IMPLICIT type

解决方案

Move the line

end program

to the end of your source file and, in its place, write the line

contains

As you have written your program it has no knowledge of the function test, which is what the compiler is telling you. I have suggested one of the ways in which you can provide the program with the knowledge it needs, but there are others. Since you are a learner I'll leave you to figure out what's going on in detail.

这篇关于函数没有隐式类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆