Can a function prototype typedef be used in function definitions?

前端 未结 2 1342
日久生厌
日久生厌 2020-12-02 20:09

I have a series of functions with the same prototype, say

int func1(int a, int b) {
  // ...
}
int func2(int a, int b) {
  // ...
}
// ...

2条回答
  •  旧巷少年郎
    2020-12-02 20:50

    A typedef defines a type, not a header (which is source code text). You have to use #define (although I don't recommend it) if you need to factor out the code for the header.

    ([Edited] The reason the first one works is that it's not defining a prototype -- it's defining a variable of the type defined by the typedef, which isn't what you want.)

提交回复
热议问题