Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
这里的问题相当简单。在定义其含义之前,您正在尝试使用
employee
。将employee
的定义移到get_employee
的定义之前。至于为什么编译器给出了一个糟糕的错误消息,我的猜测是返回类型的未定义名称以某种方式欺骗它接受对
get_employee
的调用,因为它在旧的 C 中,没有声明的函数被假定返回类型int
。然后,当它遇到
get_employee
的实际定义时,它已经有一个条目表示get_employee
returnsint
并且不接受任何参数,现在看看它是什么思考是一种重载的尝试,它也不带任何参数,但返回一个客户端
。这使它相信它所看到的是使用相同参数列表(即没有参数)但返回类型不同的重载尝试。
The problem here is fairly simple. You're trying to use
employee
before you've defined what it means. Move your definition ofemployee
before the definition ofget_employee
.As to why the compiler gives a poor error message, my guess is that somehow or other the undefined name for the return type is tricking it into accepting the call to
get_employee
as it would have in old C, where a function without a declaration is presumed to return typeint
.Then when it encounters the actual definition of
get_employee
, it has one entry already sayingget_employee
returnsint
and takes no arguments, and now sees what it's thinking is an attempt at overloading that also takes no arguments, but returns aclient
instead.And that convinces it that what it's seeing is an attempt at overloading that uses the same parameter list (i.e., no parameters) but a different return type.