Functions or methods?

后端 未结 6 1369
醉话见心
醉话见心 2021-01-19 14:09

If I\'m writing abstract data types in C, are the functions written to perform actions on these data types and exposed in the interface (.h files) called functions,

6条回答
  •  走了就别回头了
    2021-01-19 14:40

    I don't think this is a particularly useful distinction to make, but in general, you'd call them functions because the word method implies a whole bunch of OOP stuff that C doesn't provide. Like the following:

    Methods have the special property that at runtime, they have access to data stored in an instance of the class (or class instance or class object or object) they are associated with and are thereby able to control the state of the instance.

    But I've routinely heard folks who grew up on Java refer to C functions as methods and I've never once been confused about what they meant. Not even a little bit.

    You might, however, want to make the following (loose) distinctions:

    • A procedure is a block of code that does something

    • A function is a procedure that associates one or more inputs with an output

    • A method is a procedure that belongs to some class or an instance of that class

提交回复
热议问题