开发者

How could C++ compile when there is an undefined function inside source? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the in开发者_开发百科ternet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

Ok this might be a weird question.. Here's the thing, in the overloaded operator=, I used a clear() helper; But for some reason what I actually implemented was clear(Node *curr) instead of clear(), so there is no function named clear() in the entire source code. However this just compiles fine. My question is why? It didn't even throw me a warning :| Thanks in advance


It could be a compiler error, but what's more likely is that you simply forgot that you implemented such a function or the compiler has found one in a surprising place. If you have an IDE, you can attempt to use tools like Go To Definition and Go To Declaration to attempt to find the definition of the function you called.


I see two possibilities:

  1. your compiler is not linking the operator= method in your app because it is never used, so any missing functions called by it do not matter

  2. if operator= is used and it works, then you made a mistake, there is a clear() method defined. Just verify where the code goes with a source code debugger.


Easy: It found a version of clear() that it can link too.

Just because you don't see it means nothing.
It compiled correctly because:

  1. There is a header file with a function declaration of clear()
  2. You are linking against a library with the implementation of the function.

Plain and simple. If it compiled it is there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜