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

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

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

30条回答
  •  失恋的感觉
    2020-11-21 05:35

    I am not an expert, but this is what I know:

    1. Function is C language term, it refers to a piece of code and the function name will be the identifier to use this function.

    2. Method is the OO term, typically it has a this pointer in the function parameter. You can not invoke this piece of code like C, you need to use object to invoke it.

    3. The invoke methods are also different. Here invoke meaning to find the address of this piece of code. C/C++, the linking time will use the function symbol to locate.

    4. Objecive-C is different. Invoke meaning a C function to use data structure to find the address. It means everything is known at run time.

提交回复
热议问题