Functions or methods?

后端 未结 6 1371
醉话见心
醉话见心 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:29

    I've always used "method" as a synonym for "member function", which implies C++ since C has no such thing.

    On the other side of the coin however, one might argue that the role of foo_alter_state in:

    struct foo {
      // implementation stuff;
    }; 
    
    void foo_alter_state(struct foo *self);
    

    was still a method operating on foos, albeit free-standing. It's basically OOP in C, but implemented by hand.

    This perspective might be particularly true if struct foo; was only ever declared in headers, but not defined publicly anywhere.

提交回复
热议问题