What's the difference between a method and a function?

前端 未结 30 3333
粉色の甜心
粉色の甜心 2020-11-21 05:08

Can someone provide a simple explanation of methods vs. functions in OOP context?

30条回答
  •  情歌与酒
    2020-11-21 05:26

    'method' is the object-oriented word for 'function'. That's pretty much all there is to it (ie., no real difference).

    Unfortunately, I think a lot of the answers here are perpetuating or advancing the idea that there's some complex, meaningful difference.

    Really - there isn't all that much to it, just different words for the same thing.

    [late addition]


    In fact, as Brian Neal pointed out in a comment to this question, the C++ standard never uses the term 'method' when refering to member functions. Some people may take that as an indication that C++ isn't really an object-oriented language; however, I prefer to take it as an indication that a pretty smart group of people didn't think there was a particularly strong reason to use a different term.

提交回复
热议问题