Topic: 方法和函数问题

  Print this page

1.方法和函数问题 Copy to clipboard
Posted by: sunyboy001
Posted on: 2005-11-04 12:11

这个是我一直都想问的问题,在各种教材中也没能找到答案,除了必须的main方法外,我想知道什么时候需要用到函数,什么时候要用到方法?

还有方法和函数在程序中各起到什么作用,可以达到什么样的目的?

期待各位老师解答,不盛感激!

2.Re:方法和函数问题 [Re: sunyboy001] Copy to clipboard
Posted by: hualee
Posted on: 2005-11-04 12:26

这个问题真的不好怎么回答,我也不是很懂滴,希望高人来帮忙解决

3.Re:方法和函数问题 [Re: sunyboy001] Copy to clipboard
Posted by: bluecrystal
Posted on: 2005-11-04 13:06

函数和方法这两个概念在程序设计语言中没有严格区分
通常都仅仅是个习惯的叫法问题,只要不引起歧义即可

4.Re:方法和函数问题 [Re: sunyboy001] Copy to clipboard
Posted by: sunyboy001
Posted on: 2005-11-04 13:46

哦,谢谢。

是不是函数名必须和类名相同?

不过还是很想清楚的明白方法和函数在程序中各起到什么作用

5.Re:方法和函数问题 [Re: sunyboy001] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-11-04 15:24

subroutine, procedure, function, method

They are basically the same thing, used in different languages, in computer science history.

Method is usually used in OO languages, such as Java.
Function is used in c/c++/Pascal.
Procedure is used In Pascal, funtion returns a value, procedure does not.
Subroutine is used in FORTRAN/BASIC.

I just give you some examples, not a complete list.

方法和函数在程序中都起到什么作用: Make code reusable.

Subroutine is a big invention in FORTRAN language! We don't need to write the same piece of code again and again and again!!!!!!!!!!!!!!!!!!!!

It seems a simple commonplace to you and me. However, it was a great invention in computer science history!

6.Re:方法和函数问题 [Re: sunyboy001] Copy to clipboard
Posted by: sunyboy001
Posted on: 2005-11-04 16:21

呵呵---- 谢谢了

7.Re:方法和函数问题 [Re: sunyboy001] Copy to clipboard
Posted by: q_yuan
Posted on: 2005-11-05 09:59

And I have some palpability! Thank you!

8.Re:方法和函数问题 [Re: sunyboy001] Copy to clipboard
Posted by: Infinite
Posted on: 2005-11-06 03:51

只有构造函数的函数名要求和类名相同
方法和函数是同一个概念
至于起到什么作用,要看你定义的函数了。
=========================================
sunyboy001 wrote:
哦,谢谢。

是不是函数名必须和类名相同?

不过还是很想清楚的明白方法和函数在程序中各起到什么作用


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923